Friday, 9 August 2013

Collection as key in Dictionary

Collection as key in Dictionary

I have a dictionary like this:
var dic = Dictionary<Collection<MyObject>, string>
Then I add an entry like this:
dic.Add(myObjColl, "1");
where myObjColl contains a single entry
On the second run I try to add another entry to dic where myObjColl has
two entries (one of them the same as the one in the first run) and I get
an exception that the key already exists.
What am I missing here? I expect the dictionary key to be a collection and
surely two collections with different number of entries cannot be
identical.

No comments:

Post a Comment