Phương thức Char.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 Char.GetHashCode () -
using System;
public class Demo {
public static void Main(){
char val = 'H';
bool res;
Console.WriteLine("Hashcode for val = "+val.GetHashCode());
res = val.Equals('d');
Console.WriteLine("Return Value = "+res);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Hashcode for val = 4718664 Return Value = False
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ khác -
using System;
public class Demo {
public static void Main(){
char val = 'm';
bool res;
Console.WriteLine("Hashcode for val = "+val.GetHashCode());
res = val.Equals('m');
Console.WriteLine("Return Value = "+res);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Hashcode for val = 7143533 Return Value = True