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

Updated on: 08-Nov-2019

65 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements