Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

เมธอด Byte.GetHashCode() ใน C#

เมธอด Byte.GetHashCode() ใน C# ใช้สำหรับคืนค่ารหัสแฮชสำหรับอินสแตนซ์ปัจจุบัน

ไวยากรณ์

ไวยากรณ์มีดังนี้:

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