C# | Type.GetHashCode() Method
Last Updated :
18 Dec, 2019
Type.GetHashCode() Method is used to return the hash code for this instance.
Syntax: public override int GetHashCode ();
Return Value: This method returns the hash code for the current instance.
Below programs illustrate the use of Type.GetHashCode() Method:
Example 1:
using System;
using System.Globalization;
using System.Reflection;
using System.Collections.Generic;
class GFG {
public static void Main()
{
Type objType = typeof (Dictionary<, >);
int hash = objType.GetHashCode();
Console.Write( "Hashcode is {0}" , hash);
}
}
|
Output:
Hashcode is 32340152
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
get ( typeof ( int ));
get ( typeof ( string ));
get ( typeof ( decimal ));
get ( typeof ( float ));
}
public static void get (Type objType)
{
int hash = objType.GetHashCode();
Console.WriteLine( "Hashcode of {0} is {1}" , objType, hash);
}
}
|
Output:
Hashcode of System.Int32 is 18784216
Hashcode of System.String is 18793840
Hashcode of System.Decimal is 19137544
Hashcode of System.Single is 18792864
Reference:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...