Phương thức CharEnumerator.GetHashCode () trong C # trả về mã băm cho đối tượng hiện tại.
Cú pháp
public virtual int GetHashCode ();
Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức CharEnumerator.GetHashCode () -
Ví dụ
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 + " ");
// disposed
ch.Dispose();
// this will show an error since we disposed the object above
// Console.WriteLine(ch.Current);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
HashCode = 30571253 j o h n