Phương thức Byte.GetHashCode () trong C # được sử dụng để trả về mã băm cho phiên bản hiện tại.
Cú pháp
Sau đây là cú pháp -
public override int GetHashCode ();
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức 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);
}
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Hashcode = 137 Hashcode = 72 Hashcode = 86 Hashcode = 0 Hashcode = 0 Hashcode = 0 Hashcode = 0 Hashcode = 0