Which method GetHashCode()
is to prefer?
Concating all properties and
GetHashCode()
of the resultGetHashCode()
for each property and adding each
Code:
public class Foo
{
public int FooId { get; set; }
public string FooName { get; set; }
public List<string> FooList { get; set; }
public override int GetHashCode() // 1st way
{
return FooId.GetHashCode() + FooName.GetHashCode() + FooList.GetHashCode() ;
}
public override int GetHashCode() // 2nd way
{
return string.Concat(FooId, FooName, string.Concat(FooList)).GetHashCode();
}
}