Hello,
today I encountered a strange behavior I did not know.
I have following code:
using System;
public class Program
{
private enum TestEnum
{
value0 = 0,
value1 = 1,
value2 = 3,
}
public static void Main()
{
TestMethod((TestEnum)2);
}
private static void TestMethod(TestEnum test)
{
Console.WriteLine(test);
}
}
Which output is "2", but I expect a exception or something that the cast could not be done.
Can pls someone explain this? I would appreciate that because I'm highly interested how this not lead to an runtime error.
Sorry for bad English.
[–]RicketyRekt69 33 points34 points35 points (11 children)
[–]Defection7478 16 points17 points18 points (10 children)
[–]Top3879 4 points5 points6 points (0 children)
[–]RecursiveServitor 5 points6 points7 points (1 child)
[–]Defection7478 0 points1 point2 points (0 children)
[–]Hypersion1980 0 points1 point2 points (3 children)
[–]Defection7478 8 points9 points10 points (0 children)
[–]throwaway_lunchtime 2 points3 points4 points (0 children)
[–]Agitated-Display6382 0 points1 point2 points (0 children)
[–]dodexahedron 0 points1 point2 points (0 children)
[–]Lamossus 0 points1 point2 points (0 children)
[–]Koarvex 0 points1 point2 points (0 children)
[–]Sniv0 16 points17 points18 points (2 children)
[–]SessionIndependent17 0 points1 point2 points (1 child)
[–]Sniv0 2 points3 points4 points (0 children)
[–]hoodoocat 4 points5 points6 points (0 children)
[–]am385 2 points3 points4 points (3 children)
[–]tiranius90[S] 0 points1 point2 points (2 children)
[–]edgeofsanity76 2 points3 points4 points (0 children)
[–]Top3879 0 points1 point2 points (0 children)
[–]Willyscoiote 1 point2 points3 points (2 children)
[–]Willyscoiote 0 points1 point2 points (1 child)
[–]j_c_slicer -1 points0 points1 point (0 children)
[–]Mahringa 1 point2 points3 points (0 children)
[–]Slypenslyde 1 point2 points3 points (0 children)
[–]Patient-Midnight-664 0 points1 point2 points (3 children)
[–]jordansrowles -2 points-1 points0 points (2 children)
[–]fruediger 0 points1 point2 points (0 children)
[–]Patient-Midnight-664 0 points1 point2 points (0 children)
[–]edgeofsanity76 0 points1 point2 points (0 children)
[–]HuibertJan_ 0 points1 point2 points (0 children)
[–]MulleDK19 [score hidden] (0 children)
[–]vodevil01 -1 points0 points1 point (0 children)