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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。