C#语言中 的UInt16.GetHashCode()方法及示例
C#语言中的UInt16.GetHashCode()方法用于获取当前UInt16实例的HashCode。
语法
以下为语法 −
public override int GetHashCode ();
示例
现在让我们看一个示例来实现UInt16.GetHashCode()方法 −
using System; public class Demo { public static void Main(){ ushort val1 = 100; ushort val2 = UInt16.MinValue; Console.WriteLine("HashCode for val1 = "+val1.GetHashCode()); Console.WriteLine("HashCode for val2 = "+val2.GetHashCode()); } }
输出
将生成以下输出 −
HashCode for val1 = 100 HashCode for val2 = 0
示例
现在让我们看另一个示例来实现UInt16.GetHashCode()方法 −
using System; public class Demo { public static void Main(){ ushort val1 = 50; ushort val2 = UInt16.MaxValue; Console.WriteLine("HashCode for val1 = "+val1.GetHashCode()); Console.WriteLine("HashCode for val2 = "+val2.GetHashCode()); } }
输出
将生成以下输出 −
HashCode for val1 = 50 HashCode for val2 = 65535
广告