Syntax for Enum
enum Specifier
{
value1,
value2,
value3
}
Here in above example, we are having an enum with name Specifier, and some constant defined under the enum. Here when we access this enum we will get the value same as enum value which is value1. Let's run and check the output. Console.WriteLine(Specifier.value1);
In above code I am trying to contestant value of enum. Let's run the code and check the output. Ones we run the code we will get the value1.As all we know we majorly use enum in condition. Now let's check the condition.
In above code we can see that we are having error. It will whenever we are trying put value in condition. Now to resolve this we need to define the enum with string value. So here the most important thing that we cannot directly us the enum. As we know enum define the constant. So, for defining the string value in enum we need to use class constant. Refer the below code.
Enum Of String Type
public static class Specifier
{
public const string value1 = "value1";
public const string value2 = "value2";
public const string value3 = "value3";
}
In above code I have defined a class of static type and in this class, I have defined few constant, which will act as the enum value. Now let's put the value in condition.