In coreclr repo this comment :
Action: our hash return algorithm is a bit more complicated. We look for the first non-static field and get its hashcode. If the type does not have non-static fields, we return the hash of the type. We cannot hashcode a static member, because if this element is of the same type as the original type, we end up with an infinite loop.
However, the code is not there, and it seems that not quite what is happening. Example:
using System;
struct Foo
{
public string x;
public string y;
}
class Test
{
static void Main()
{
Foo foo = new Foo();
foo.x = "x";
foo.y = "y";
Console.WriteLine(foo.GetHashCode());
Console.WriteLine("x".GetHashCode());
Console.WriteLine("y".GetHashCode());
}
}
The output in my field is:
42119818
372029398
372029397
y
- foo
.
, int
, , .
: , , , , . , / , GetHashCode
Equals
( IEquatable<T>
).