check if value already exists

Bublik picture Bublik · May 3, 2012 · Viewed 68.6k times · Source

I have dictionary which holds my books:

Dictionary<string, book> books

Book definiton:

class book
{
    string author { get; set; }

    string title { get; set; }
} 

I have added some books to the dictionary.

How can I check if there is a book in the Dictionary that matches the title provided by the user?

Answer

Brendan picture Brendan · May 3, 2012
books.ContainsKey("book name");