C#中的Double.GetHashCode()方法用于返回此实例的哈希码。
语法如下-
public override int GetHashCode ();
现在让我们看一个例子-
using System; public class Demo { public static void Main(){ double d1 = 150d; object ob1 = 1/2; Console.WriteLine("Double1 Value = "+d1); Console.WriteLine("Object Value = "+ob1); Console.WriteLine("Are both the values equal? = "+d1.Equals(ob1)); Console.WriteLine("HashCode of Double1 Value = {0}", d1.GetHashCode()); } }
输出结果
这将产生以下输出-
Double1 Value = 150 Object Value = 0 Are both the values equal? = False HashCode of Double1 Value = 1080213504
现在让我们来看另一个示例-
using System; public class Demo { public static void Main(){ double d = 10d; Console.WriteLine("Double Value = "+d); Console.WriteLine("HashCode of Double Value = {0}", d.GetHashCode()); } }
输出结果
这将产生以下输出-
Double Value = 10 HashCode of Double Value = 1076101120