Char.GetHashCode() Method with Examples in C#



The Char.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 Char.GetHashCode() method −

using System;
public class Demo {
   public static void Main(){
      char val = 'H';
      bool res;
      Console.WriteLine("Hashcode for val = "+val.GetHashCode());
      res = val.Equals('d');
      Console.WriteLine("Return Value = "+res);
   }
}

Output

This will produce the following output −

Hashcode for val = 4718664
Return Value = False

Example

Let us now see another example −

using System;
public class Demo {
   public static void Main(){
      char val = 'm';
      bool res;
      Console.WriteLine("Hashcode for val = "+val.GetHashCode());
      res = val.Equals('m');
      Console.WriteLine("Return Value = "+res);
   }
}

Output

This will produce the following output −

Hashcode for val = 7143533
Return Value = True

Advertisements