要获取当前UInt32实例的HashCode,代码如下-
using System; public class Demo { public static void Main() { uint val1 = 100; uint val2 = UInt16.MinValue; Console.WriteLine("val1的HashCode = "+val1.GetHashCode()); Console.WriteLine("val2的HashCode = "+val2.GetHashCode()); } }
输出结果
这将产生以下输出-
val1的HashCode = 100 val2的HashCode = 0
让我们看另一个例子-
using System; public class Demo { public static void Main() { uint val1 = 50; uint val2 = UInt16.MaxValue; Console.WriteLine("val1的HashCode = "+val1.GetHashCode()); Console.WriteLine("val2的HashCode = "+val2.GetHashCode()); } }
输出结果
这将产生以下输出-
val1的HashCode = 50 val2的HashCode = 65535