僅用於雜湊基礎集合的鍵:Hashtable、Dictionary、HashSet。其他情況(UI 控制項、資料庫連線、檔案控制代碼)不應作鍵。
int 雜湊碼Equals 精確比對a.Equals(b) == true → a.GetHashCode() == b.GetHashCode()GetHashCode() 恆定回傳相同值int 範圍均勻分布public struct MyStruct
{
private string _msg; // 第一欄位
private int _id;
private DateTime _epoch;
}
// 預設雜湊碼 = _msg.GetHashCode()
MyStruct s = new MyStruct();
bool same = s.GetHashCode() == s._msg.GetHashCode(); // 永遠 true
後續部分驗證三大規則於 ValueType 預設實作。