Decimal.GetHashCode() Method in C# with Examples

CsharpServer Side ProgrammingProgramming

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

Syntax

Following is the syntax −

public override int GetHashCode ();

Example

Let us now see an example to implement the Decimal.GetHashCode() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val = 135269.38193M;
      Console.WriteLine("Decimal Value = {0}", val);
      Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );
   }
}

Output

This will produce the following output −

Decimal Value = 135269.38193
HashCode = 1328665595

Example

Let us now see another example to implement the Decimal.GetHashCode() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val = Decimal.MaxValue;
      Console.WriteLine("Decimal Value = {0}", val);
      Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );
   }
}

Output

This will produce the following output −

Decimal Value = 79228162514264337593543950335
HashCode = 1173356544
raja
Published on 12-Nov-2019 09:20:43
Advertisements