using System;public class EnumTest {enum Result {Fail,Pass};public static void Main() {Console.WriteLine(Result.Pass);int passIntVal = (int) Result.Pass;Console.WriteLine("The int value of Pass is " + passIntVal);int failIntVal = Convert.ToInt32(Result.Fail);Console.WriteLine("The int value of Fail is " + failIntVal);}}
Let’s break down the code written above:
enum object Result with two values, Fail and Pass. The default underlying data type for an enum is int . So the value of Fail is 0 and the value of Pass is 1.Result.Pass enum into an int. This returns the respective int value of the enum.ToInt32 method of the Convert class to convert the enum value Result.Fail to an int value. This method returns 0 as a result.
.