the use of enum.

  • Thread starter Thread starter developer1996
  • Start date Start date
D

developer1996

Can someone please explain to me why you cannot use enum
at the method level to define a type. The declaration
seems to only work at the class level. From my
understanding enums are classified as a user define type.
I do understand that in order to define a type you have to
derive it from object or a struct. But the question still
remains why only at class level. I guess the only way to
really define a type within a class is to define an inner
class and then define an enum type within the inner class.
But the scope of the enum type would be private to the
parent class. Simple concept but I just want to know why?
 
Thus spake developer1996:
I guess the only way to
really define a type within a class is to define an inner
class and then define an enum type within the inner class.

Why not just create the enum at the namespace level?
 
developer1996 said:
Can someone please explain to me why you cannot use enum
at the method level to define a type.

Do you mean defining an enumeration within a method? What's the use-
case here?
The declaration
seems to only work at the class level. From my
understanding enums are classified as a user define type.
I do understand that in order to define a type you have to
derive it from object or a struct. But the question still
remains why only at class level. I guess the only way to
really define a type within a class is to define an inner
class and then define an enum type within the inner class.
But the scope of the enum type would be private to the
parent class. Simple concept but I just want to know why?

I really don't get what you're trying to do. Could you give an example
of the kind of code you wish you could write?
 
I like to use the enumeration type for creating more
understandable and easily read code because I tend to
forget what I was doing 3 months down the road. The
enumeration type is so specific to this method it isn't
used any where else in the class nor is the enumeration
used by any other class. It would make the code appear
much clearer if I could do this. My question is not can I
do this. I realize I can't but why? This will give me a
better understanding of what is going on underneath the
covers.
 
Back
Top