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

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

เมธอด CharEnumerator.GetHashCode() ใน C# คืนค่า Hash Code สำหรับออบเจ็กต์ปัจจุบัน

ไวยากรณ์

public virtual int GetHashCode();

ตัวอย่าง

using System;

public class Demo
{
    public static void Main()
    {
        string strNum = "john";
        CharEnumerator ch = strNum.GetEnumerator();
        
        Console.WriteLine("HashCode = " + ch.GetHashCode());
        
        while (ch.MoveNext())
            Console.Write(ch.Current + " ");
        
        ch.Dispose();
    }
}

ผลลัพธ์

HashCode = 30571253
j o h n

การใช้งาน: Hash Code ใช้สำหรับการเก็บใน Hash-based Collections (เช่น HashSet, Dictionary) โดยทั่วไป CharEnumerator ไม่ได้ถูกนำไปเก็บใน Collection โดยตรง