Phương thức Decimal.GetHashCode() trong C# được sử dụng để trả về mã băm (hash code) cho thể hiện hiện tại.
Cú pháp
Dưới đây là cú pháp:
public override int GetHashCode ();
Ví dụ 1
Hãy xem ví dụ sau để triển khai phương thức Decimal.GetHashCode():
using System;
public class Demo {
public static void Main(){
Decimal val = 135269.38193M;
Console.WriteLine("Decimal Value = {0}", val);
Console.WriteLine("HashCode = {0}", (val.GetHashCode()));
}
}
Đầu ra
Chương trình sẽ cho ra kết quả sau:
Decimal Value = 135269.38193 HashCode = 1328665595
Ví dụ 2
Ví dụ khác triển khai phương thức Decimal.GetHashCode() với MaxValue:
using System;
public class Demo {
public static void Main(){
Decimal val = Decimal.MaxValue;
Console.WriteLine("Decimal Value = {0}", val);
Console.WriteLine("HashCode = {0}", (val.GetHashCode()));
}
}
Đầu ra
Chương trình sẽ cho ra kết quả sau:
Decimal Value = 79228162514264337593543950335 HashCode = 1173356544