A
Al Meadows
I'm using a generic Dictionary object where it is described as:
Dictionary<this, that> stuff = new Dictonary<this, that>()
Where THIS is a class with several property values.
This works fine as far as adding the key/value pairs to the dictionary.
The problem is when I contruct a new THIS object:
This this = new This();
this.a = "a";
this.b = "b";
and try to get a hit on:
if (stuff.ContainsKey(this))
{
...
}
Note: It works GREAT if I add this to the 'stuff' dictionary and then look
for the key, but not when I contruct a new key and try to match it to the
dictionary.
From research, I understand that it is because the dictionary object stores
a hash table value instead of the actual object as the key or something like
that and that is why they won't find it when I use Contains.
So, how do I work around this?
Dictionary<this, that> stuff = new Dictonary<this, that>()
Where THIS is a class with several property values.
This works fine as far as adding the key/value pairs to the dictionary.
The problem is when I contruct a new THIS object:
This this = new This();
this.a = "a";
this.b = "b";
and try to get a hit on:
if (stuff.ContainsKey(this))
{
...
}
Note: It works GREAT if I add this to the 'stuff' dictionary and then look
for the key, but not when I contruct a new key and try to match it to the
dictionary.
From research, I understand that it is because the dictionary object stores
a hash table value instead of the actual object as the key or something like
that and that is why they won't find it when I use Contains.
So, how do I work around this?