C# program to get the hash-code of enum constants
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to get the hash-code of enum constants is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created an enum COLOR that contain constants with color names. Here, we also created a class EnumDemo that contains two static methods PrintHashCode() and Main().
In the PrintHashCode() method, we created a switch block, here we printed the hash-code of color constants based on enum constant passed into the method.
In the Main() method, we called the PrintHashCode() method with different values of a COLOR enum.