29
1
using System;
2
3
public class Program
4
{
5
enum BallColor
6
{
7
White=0,
8
Red = 1,
9
Green = 2
10
}
11
public static void Main()
12
{
13
//get enum
14
BallColor ballColor = BallColor.White;
15
string enumValue = ballColor.ToString();
16
17
//print enum to string value
18
Console.WriteLine(enumValue);
19
20
Console.WriteLine("using For loop");
21
//loop through enums using for loop
22
for (BallColor bc = BallColor.White; bc <= BallColor.Green; bc++)
23
{
24
string val = bc.ToString();
25
//print enum value using .ToString()
26
Console.WriteLine(val);
27
}
28
}
29
}
Cached Result
White
using For loop
White
Red
Green
using For loop
White
Red
Green