M
Matthias Kientz
I have a class which should override the GetHashcode() function, which
look like this:
public class A
{
public string str1;
public string str2;
//other methods...
public override int GetHashCode()
{
return ???;
}
}
The instance members str1 and str2 are the "primary keys" of my class.
All instances of A with the same values for str1 and str2 should return
the same hash code. The implementation should be also as fast as possible.
An instance with A.str1 = "x" and A.str2 = "y" should return a different
hashcode as an instance with A.str1 = "y" and A.str2 = "x".
How to implement such a behavior and ensure that my hash code is
consistent? How does the implementation of System.String do this?
Thanks for any help and suggestions.
Matthias
look like this:
public class A
{
public string str1;
public string str2;
//other methods...
public override int GetHashCode()
{
return ???;
}
}
The instance members str1 and str2 are the "primary keys" of my class.
All instances of A with the same values for str1 and str2 should return
the same hash code. The implementation should be also as fast as possible.
An instance with A.str1 = "x" and A.str2 = "y" should return a different
hashcode as an instance with A.str1 = "y" and A.str2 = "x".
How to implement such a behavior and ensure that my hash code is
consistent? How does the implementation of System.String do this?
Thanks for any help and suggestions.
Matthias