When generating hashcodes for a class, is it ok to use the hashcodes of that class's members? Here is a sample class:
class Sample
{
private readonly string _strA, _strB;
public Sample(string strA, string strB)
{
this._strA = strA;
this._strB = strB;
}
public override int GetHashCode()
{
return (this._strA + "###" + this._strB).GetHashCode();
}
}
I think this will work as long as neither _strA nor _strB contain the string "###". I'm not totally sure though as I don't know the specifics of how hashcodes are generated on strings.
I saw a solution in the post at Create a hashcode of two numbers that I could tailor for my purposes, but I think that my solution is more simple (as long as neither string contains "###").