Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức Byte.GetHashCode() trong C#

Phương thức Byte.GetHashCode() trong C# được dùng để trả về mã băm (hash code) cho thể hiện hiện tại.

Cú pháp

Cú pháp như sau:

public override int GetHashCode();

Ví dụ - HashCode các byte trong mảng

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);
        }
    }
}

Kết quả

Hashcode = 137
Hashcode = 72
Hashcode = 86
Hashcode = 0
Hashcode = 0
Hashcode = 0
Hashcode = 0
Hashcode = 0