Normally, when you call the ToString method on a variable that stores an integer value, the value of the integer is displayed.
1
2
3
| int x = 42;Console.WriteLine(x.ToString()); // Displays: 42Console.WriteLine(x); // Same thing--ToString implicitly called |
If you call ToString on an enum type variable, however, the textual name of the enumerated member is displayed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| public enum Mood { Crabby = -5, Happy = 5, Petulant = -2, Elated = 10};static void Main(){ Mood myMood = Mood.Crabby; Mood dogsMood = Mood.Elated; Console.WriteLine(myMood); // ToString implicitly called; displays: Crabby Console.WriteLine(dogsMood); // Displays: Elated} |

