Answer the question
In order to leave comments, you need to log in
How to override Object.GetHashCode()?
How can I override the GetHashCode() method when using a dictionary?
I am reading this :
The type used as the dictionary key must override the GetHashCode() method of the Object class.
Answer the question
In order to leave comments, you need to log in
If your key is a string, i.e. string type - nothing needs to be redefined. string already has GetHashCode implemented.
Override in your class
public override int GetHashCode()
{
return ...;
}
if your key is a string, then take the hash of the string:
class Test
{
public string Name;
public override int GetHashCode()
{
return Name.GetHashCode();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question