Skip to content
Related Articles

Related Articles

How to get the hashcode for enum in C#?

Improve Article
Save Article
  • Last Updated : 23 Jul, 2019
Improve Article
Save Article

Enum.GetHashCode Method is used to get the HashCode for the value of the current instance. This method is inherited from the Object class.


public override int GetHashCode ();

Returns: This method returns the 32-bit signed integer hash code.


// 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
        Color c2 = Color.Black;
        Console.Write("Hashcode of Enum Constant " + c2 + " : ");
        // Using the GetHashCode Method


HashCode of Enum Constant Blue : 0
Hashcode of Enum Constant Black : 1


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!