Byte.GetHashCode() Method in C#


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

using System;
public class Demo {
   public static void Main(){
      long val = 5654665;
      byte[] arr = BitConverter.GetBytes(val);
      for (int i = 0; i < arr.Length; i++) {
         int res = arr[i].GetHashCode();
         Console.WriteLine("Hashcode = "+res);
      }
   }
}

Output

This will produce the following output −

Hashcode = 137
Hashcode = 72
Hashcode = 86
Hashcode = 0
Hashcode = 0
Hashcode = 0
Hashcode = 0
Hashcode = 0
raja
Published on 08-Nov-2019 10:50:49
Advertisements