C# 中的 Int16.GetHashCode() 方法用於返回當前實例的哈希碼。
用法
以下是語法 -
public override int GetHashCode ();
示例
現在讓我們看一個實現 Int16.GetHashCode() 方法的例子 -
using System;
public class Demo {
public static void Main(){
short val1 = 20;
short val2 = 25;
Console.WriteLine("Value1 = "+val1);
Console.WriteLine("Value2 = "+val2);
Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());
Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());
Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
}
}
輸出
這將產生以下輸出 -
Value1 = 20 Value2 = 25 HashCode for value1 = 1310740 HashCode for value2 = 1638425 Are they equal? = False
示例
現在讓我們看另一個實現 Int16.GetHashCode() 方法的例子 -
using System;
public class Demo {
public static void Main(){
short val1 = 0;
short val2 = Int16.MaxValue;
Console.WriteLine("Value1 = "+val1);
Console.WriteLine("Value2 = "+val2);
Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());
Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());
Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
}
}
輸出
這將產生以下輸出 -
Value1 = 0 Value2 = 32767 HashCode for value1 = 0 HashCode for value2 = 2147450879 Are they equal? = False
相關用法
- C# Int16.GetHashCode用法及代碼示例
- C# Int16.GetTypeCode用法及代碼示例
- C# Int16.ToString()用法及代碼示例
- C# Int16.MaxValue用法及代碼示例
- C# Int16.MinValue用法及代碼示例
- C# Int16.Parse(String)用法及代碼示例
- C# Int16.CompareTo()用法及代碼示例
- C# Int16.Equals用法及代碼示例
- C# Int32.CompareTo用法及代碼示例
- C# Int64.Equals用法及代碼示例
- C# Int32.GetHashCode用法及代碼示例
- C# Int32.Parse(String)用法及代碼示例
- C# Int64.Parse(String)用法及代碼示例
- C# Int64.GetHashCode用法及代碼示例
- C# Int64.GetTypeCode用法及代碼示例
- C# Int64.CompareTo用法及代碼示例
- C# Int32.GetTypeCode用法及代碼示例
- C# Int64.MinValue用法及代碼示例
- C# Int64.ToString()用法及代碼示例
- C# Int32.MinValue用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 Int16.GetHashCode() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。