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