Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing Enum To Method
Message
From
17/03/2010 12:54:32
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01455109
Message ID:
01455122
Views:
33
>>>>>I created a Web Control. In it is this enum:
>>>>>
>>>>>
>>>>>public enum PageMode
>>>>>{
>>>>>    New,
>>>>>    Edit,
>>>>>    View
>>>>>}
>>>>>
>>>>>
>>>>>From outside the control I'm trying to do:
>>>>>
>>>>>
>>>>>crlRoles.SetPageMode(crlRoles.PageMode.Edit);
>>>>>
>>>>>
>>>>>I'm getting a compile error "'PageMode': cannot reference a type through an expression; try 'crlRoles.PageMode' instead".
>>>>>
>>>>>How do I do this in an ASP.Net app?
>>>>
>>>>I generally find it better not to place enums inside of classes unless you only plan on using it within the class. That doesn't seem to be the case here, so why not put the enum in its own file and move it outside the class. In web apps I have a folder called Enums and I put them all in there where they are used in the web pages.
>>>>Tim
>>>
>>>In a stand-alone CS file?
>>
>
>>>Yes, it does not need to be in a class.
>Where else can you put them?

It all depends on what you are using them for. I will rarely ever put them inside a class but you can if it is only being used inside that class it might make sense. Since you can put them in a cs file all by itself which is what I do you could also create a cs file called Enums.cs and put all of them in the same file. I create Enums for lots of things because they help to prevent mistyping for yourself.

I also create compoonents that I expose to other applications. I use enums so they can only provide me specific parameters when using methods.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform