C#中的UInt32.GetHashCode()方法用于获取当前UInt32实例的HashCode。
以下是语法-
public override int GetHashCode ();
现在让我们看一个实现UInt32.GetHashCode()方法的示例-
using System; public class Demo { public static void Main(){ uint val1 = 100; uint 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
现在让我们来看另一个实现UInt32.GetHashCode()方法的示例-
using System; public class Demo { public static void Main(){ uint val1 = 50; uint 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