Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to put Enums

Status
Not open for further replies.

rrhandle

Programmer
Dec 26, 2001
193
0
0
US
I'm using Visio and its UML tools to help convert a VB6 application to a ASP.NET application. In the original VB6 app, enums were placed inside particular classes that they were associated. When I recreated this structure in ASP.NET using VS.NET, it worked fine, but when I reversed engineered it into Visio, it threw errors: enums need to be in there own separate classes. Is this the way it should be done in the .NET world--which I admit I am completely new to.

The only thing worse than being alone, is wishing you were.
 
In C#, enums can exist in their own source files as well as being members of a class. You can declare one whereever you can declare a value type.
MSDN said:
An enum declaration declares a new enum type. An enum declaration begins with the keyword enum, and defines the name, accessibility, underlying type, and members of the enum.

enum-declaration:
attributesopt enum-modifiersopt enum identifier enum-baseopt enum-body ;opt
enum-base:
; integral-type
enum-body:
{ enum-member-declarationsopt }
{ enum-member-declarations , }
Each enum type has a corresponding integral type called the underlying type of the enum type. This underlying type must be able to represent all the enumerator values defined in the enumeration. An enum declaration may explicitly declare an underlying type of byte, sbyte, short, ushort, int, uint, long or ulong. Note that char cannot be used as an underlying type. An enum declaration that does not explicitly declare an underlying type has an underlying type of int.
The VB.NET language reference (I had to look it up) says:
MSDN said:
Used at module, class, or structure level to declare an enumeration and define the values of its members.

[ <attrlist> ] [{ Public | Protected | Friend | Protected Friend |
Private }] [ Shadows ] Enum name [ As type ]
[<attrlist1>] membname1 [ = initexpr1 ]
[<attrlist2>] membname2 [ = initexpr2 ]
...
[<attrlistn>] membnamen [ = initexprn ]
End Enum

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks, Chip. I read the same thing, but thought I might be missing something due to the error I got when viewing the project in Visio. I assume this is really a Visio issue which I will pursue on another day.

Thanks again!

The only thing worse than being alone, is wishing you were.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top