Int64.GetHashCode 方法在 C# 中用法带示例
C# 中的 Int64.GetHashCode() 方法用于返回为此实例获取哈希代码。
语法
以下是语法 −
public override int GetHashCode ();
示例
现在,我们来看一个实现 Int64.GetHashCode() 方法的示例 −
using System; public class Demo { public static void Main(){ long val1 = 8768768768; long val2 = 7889765555; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); Console.WriteLine("Are they equal? = "+val1.Equals(val2)); Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode()); Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode()); } }
输出
这将生成以下输出 −
Value1 = 8768768768 Value2 = 7889765555 Are they equal? = False Value1 (HashCode) = 178834178 Value2 (HashCode) = -700169038
示例
现在,我们来看另一个实现 Int64.GetHashCode() 方法的示例 −
using System; public class Demo { public static void Main(){ long val1 = 0; long val2 = Int64.MaxValue; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); Console.WriteLine("Are they equal? = "+val1.Equals(val2)); Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode()); Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode()); } }
输出
这将生成以下输出 −
Value1 = 0 Value2 = 9223372036854775807 Are they equal? = False Value1 (HashCode) = 0 Value2 (HashCode) = -2147483648
广告