31
1
using System;
2
3
public class Program
4
{
5
enum Week
6
{
7
Monday,
8
Tuesday,
9
Wednesday,
10
Thursday,
11
Friday,
12
Saturday,
13
Sunday
14
}
15
16
public static void Main()
17
{
18
string day1 = "Monday";
19
string day2 = "MONDAY";
20
string day3 = "SomeOtherDay";
21
22
Week weekDay1 = (Week)Enum.Parse(typeof(Week), day1);
23
Week weekDay2 = (Week)Enum.Parse(typeof(Week), day2, true); // ignore case
24
25
// the following will throw an exception
26
//Week weekDay3 = (Week) Enum.Parse(typeof(Week), day3);
27
28
Console.WriteLine(weekDay1);
29
Console.WriteLine(weekDay2);
30
}
31
}
Cached Result
Compilation error (line 30, col 31): Unexpected character '$'
Compilation error (line 43, col 39): Unexpected character '$'
Compilation error (line 94, col 31): Unexpected character '$'
Compilation error (line 99, col 35): Unexpected character '$'
Compilation error (line 109, col 39): Unexpected character '$'
Compilation error (line 43, col 39): Unexpected character '$'
Compilation error (line 94, col 31): Unexpected character '$'
Compilation error (line 99, col 35): Unexpected character '$'
Compilation error (line 109, col 39): Unexpected character '$'