Firstly, why are you using a hash table and not a generic Dictionary<,>
?
Regardless, your problem is that the hash table calls ((object)"abc").Equals(moo)
, which returns false, of course. You can override this behavior by passing your own implementation of IEqualityComparer
one of the HashTable
constructors with the IEqualityComparer
parameter.
Since, as you already noted, you are trying to avoid changing obsolete code, you may not be able to replace the existing hash table with those who have custom IEqualityComparer. If this is true, then I think the answer is that you cannot do what you would like to do.
Since you are developing this "moo" class, I assume that you have control over the code that passes the moo class to the index index of the hash table. If this is true, you can simply call ToString()
on the object you pass to the index, and, of course, override ToString
in Moo
.
phoog source share