C#中的Byte.GetHashCode()方法用于返回当前实例的哈希码。
以下是语法-
public override int GetHashCode ();
现在让我们看一个实现Byte.GetHashCode()方法的示例-
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);
}
}
}输出结果
这将产生以下输出-
Hashcode = 137 Hashcode = 72 Hashcode = 86 Hashcode = 0 Hashcode = 0 Hashcode = 0 Hashcode = 0 Hashcode = 0