The scope of a variable is limited to the method if I declare a variable inside that method (which is not accessible outside the method). Is it possible to define an enum
in a similar way?
The code won't compile if I do this:
void someMethod()
{
enum MyEnum
{
val1,
val2,
Val3
}
}
What might be the reason for this? I have extended my try with struct
, and the same thing is happening (code won't compile). Hence I came to a conclusion that "Named types cannot be defined inside a method".
But I don't have any justification for this conclusion. What is the reason for why it is not allow me to define named types inside the method?
Note: It is not permitted, the code won't compile. Here my question is why it is not permitted.