I get that my enum in this example is an Integer, but this still seems very wrong. I expected an ArgumentException:
class Program {
enum Testing {
Zeroth,
First,
Second,
Third
}
static void Main(string[] args) {
Testing result = Testing.Zeroth;
var toTest = "17";
result = (Testing)Enum.Parse(typeof(Testing), toTest);
Console.WriteLine(result); // Output: 17
Console.ReadLine();
}
}
The following does throw the argument exception I expected:
class Program {
enum Testing {
Zeroth,
First,
Second,
Third
}
static void Main(string[] args) {
Testing result = Testing.Zeroth;
var toTest = "Seventeen";
result = (Testing)Enum.Parse(typeof(Testing), toTest);
Console.WriteLine(result);
Console.ReadLine();
}
}
And that takes the cake for me.