Decimal.GetHashCode Method in C# with Examples
Last Updated :
19 Mar, 2019
Decimal.GetHashCode method is used to get the HashCode for the current Decimal instance.
Syntax: public override int GetHashCode ();
Return Value: This method returns a 32-bit signed integer hash code.
Below programs illustrate the use of the above discussed-method:
Example 1:
using System;
class GFG {
public static void Main()
{
Decimal dec1 = 214748.78549M;
int result = dec1.GetHashCode();
Console.WriteLine( "HashCode for Decimal is: {0}" ,
result);
}
}
|
Output:
HashCode for Decimal is: 161795526
Example 2:
using System;
class GFG {
public static void Main()
{
result(Decimal.MinValue);
result(Decimal.MaxValue);
}
public static void result( decimal val)
{
int code = val.GetHashCode();
Console.WriteLine( "HashCode for {0} is {1}" ,
val, code);
}
}
|
Output:
HashCode for -79228162514264337593543950335 is -974127104
HashCode for 79228162514264337593543950335 is 1173356544
Reference:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...