c# - What can cause dictionary.ContainsKey(dictionary.Keys.First()) to return false? -
dictionary.keys.first().gethashcode() == dictionary.keys.first().gethashcode()
returns true dictionary.keys.first() == dictionary.keys.first()
returns true
what's missing? why can't dictionary find object?
type of dictionary: dictionary<exceptionwrapper<exception>, list<int>>
.
here implementation of exceptionwrapper.equals
, exceptionwrapper.gethashcode
:
public override int gethashcode() { return (typeof(texception).fullname + exception.message + exception.stacktrace).gethashcode(); } public override bool equals(object obj) { return obj exceptionwrapper<texception> && (obj exceptionwrapper<texception>).gethashcode() == gethashcode(); }
the key first added dictionary<,>
when had 1 hash code. after object "mutated" give state hash code new number.
the dictionary<,>
therefore in invalid state.
do not mutate object might key in hashtable somewhere, in way changes hash code of object.
Comments
Post a Comment