这种上源码看看就比较清楚了。先看Object对HashObject的描述: // GetHashCode is intended to serve as a hash function for this object. // Based on the contents of the object, the hash function will return a suitable // value with a relatively random distribution over the various inputs. // // The default implementation returns the [....] block index for this instance. // Calling it on the same object multiple times will return the same value, so // it will technically meet the needs of a hash function, but it's less than ideal. // Objects (& especially value classes) should override this method. public virtual int GetHashCode() { return RuntimeHelpers.GetHashCode(this); } 再看string的描述 // Gets a hash code for this string. If strings A and B are such that A.Equals(B), then // they will return the same hash code. 从设计来说,GetHashCode这个方法是用于区分不同对象的标识。Object中设计是按照对象的分配的内存计算的HashCode,如果你设计的类不重写这个方法,它将使用Object的默认方法来获取HashCode。 而文档也说得很清楚,如果你要在自己的类中重写Equals方法进行对象一致判断时,那么你必须要同时设计自己的GetHashCode方法,因为判断对象是否一致,最终是通过GetHashCode方法来判断的(PS:也就是说,两个对象是不是同一个,其实是允许你自己定规则来决定)。 而你提到的string的HashCode一定是同一个值,正是因为它重写了Equals方法,它并不以同一对象作为Equals的条件,而是以对象具体的字符串的值,所以它同时也重写了GetHashCode。比如你的string a = "1234"; 你每次运行a.GetHashCode()得到同一个值,因为它的内容没有变,所以按它以内容计算HashCode的算法,这个HashCode也不会变。