Generic Dictionary KeyValue pair with a boolean?

j0rd4nn

New member
Joined
Dec 18, 2013
Messages
4
Programming Experience
5-10
Okay, so heres part of the code I have:

Form1.cs:


Book.cs:


I'm trying to add a Boolean value with each keyvalue pair I add. Is this even possible?. I need to be able to add/remove books to the dictionary, and also for each book to have a loan status denoted by a Boolean.

I'm using a Windows Form if that's of any help.
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,150
Location
Sydney, Australia
Programming Experience
10+
Firstly, is 'book' really a good name for that Dictionary? Does it represent a single book? Certainly not, so it's a bad name. The name should make it clear what the variable holds.

As for the question, it's basically a moot point. You shouldn't be using a Dictionary<string, string> anyway. You already have a Book class and that class already has a Boolean OnLoan property. Use them. You should be using a Dictionary<string, Book> or, if that 'input' value corresponds to the title of the book, just a List<Book>. The Book objects in the collection then contain the information about whether that book is on loan or not, which is the whole point of having a class in the first place.
 

j0rd4nn

New member
Joined
Dec 18, 2013
Messages
4
Programming Experience
5-10
Lovely. After a few reads I understand what you're saying.

Thanks a lot, you've been a great help.
 
Top Bottom