How to get the hashcode for enum in C#? Last Updated : 23 Jul, 2019 Comments Improve Suggest changes Like Article Like Report Enum.GetHashCode Method is used to get the HashCode for the value of the current instance. This method is inherited from the Object class. Syntax: public override int GetHashCode (); Returns: This method returns the 32-bit signed integer hash code. Example: csharp // C# program to illustrate the // Enum.GetHashCode() Method using System; class GFG { enum Color {Blue, Black}; // Main Method public static void Main(String[] args) { Color c1 = Color.Blue; Console.Write("HashCode of Enum Constant " + c1 + " : "); // Using the GetHashCode() Method Console.WriteLine(c1.GetHashCode()); Color c2 = Color.Black; Console.Write("Hashcode of Enum Constant " + c2 + " : "); // Using the GetHashCode Method Console.WriteLine(c2.GetHashCode()); } } Output: HashCode of Enum Constant Blue : 0 Hashcode of Enum Constant Black : 1 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.enum.gethashcode?view=netframework-4.8 Comment More infoAdvertise with us Next Article How to get the hashcode for enum in C#? A ankita_saini Follow Improve Article Tags : C# CSharp-method CSharp-Enum-Class Similar Reads C# | How to get the HashCode for the string GetHashCode() method is used to get the hash code of the specified string. When you apply this method to the string this method will return a 32-bit signed integer hash code of the given string. Syntax: public override int GetHashCode (); Return Value: The return type of this method is System.Int32. 2 min read How to get the typecode for enum in C#? Enum.GetTypeCode Method is used to get the type code of the underlying type of this enumeration member. Syntax: public TypeCode GetTypeCode (); Returns: This method returns type code of the underlying type of this instance. Exception: This method will give InvalidOperationException if the enumeratio 1 min read C# | How to get the HashCode of the tuple? A tuple is a data structure which gives you the easiest way to represent a data set. You can also get the hash code of the tuple by using the GetHashCode Method. This method will return the hash code of the given tuple object. Syntax: public override int GetHashCode (); Return Type: The return type 2 min read C# | CharEnumerator.GetHashCode() Method GetHashCode() Method serves as the default hash function and returns a hash code for the current object. This method is inherited from the Object class. Syntax: public virtual int GetHashCode (); Return Value: This method returns an Int32 value corresponding to the hash code of the current object. B 2 min read DateTime.GetHashCode() Method in C# This method is used to return the hash code for this instance. Syntax: public override int GetHashCode (); Return Value: This method returns a 32-bit signed integer hash code. Below programs illustrate the use of DateTime.GetHashCode() Method: Example 1: csharp // C# program to demonstrate the // Da 1 min read Like