Double.GetHashCode() Method in C#


The Double.GetHashCode() method in C# is used to return the hash code for this instance.

Syntax

The syntax is as follows −

public override int GetHashCode ();

Example

Let us now see an example −

 Live Demo

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());
   }
}

Output

This will produce the following output −

Double1 Value = 150
Object Value = 0
Are both the values equal? = False
HashCode of Double1 Value = 1080213504

Example

Let us now see another example −

 Live Demo

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());
   }
}

Output

This will produce the following output −

Double Value = 10
HashCode of Double Value = 1076101120

Updated on: 03-Dec-2019

57 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements