I've created a simple enum in C# as follows
enum Direction
{
North,
South,
East,
West
}
Now I'm creating a variable of this Direction enum as :
Direction D = (Direction)3;
Console.WriteLine(D.ToString());
Every thing goes fine and code works as expected and gives the following as output.
West
but now if I changes the code a bit like :
Direction D = (Direction)8;
Console.WriteLine(D.ToString());
it gives following as output :
8
So finally the questions came in my mind are:
- Why this is getting done when the max acceptable value is 3.
- If its getting accepted at time of compiling then why it's not throwing any exception while .net framework is such a robust framework yet.
- And at last but not the least, if all is not going expected why it's giving output 8.
Thanks in advance buddies :)
GURU