enum data type

G

guoqi zheng

Trying to declare a enum datatype.

Below works

Public Enum EnumCharSet
IBM037
IBM437
IBM500
End Enum

When I add a new string with a "-", error occur says that "End of statement
expected"

For example
Public Enum EnumCharSet
IBM037
IBM437
IBM500
ASMO-708
End Enum

Does not work because ASMO-708 has a "-" there.

What went wrong and what should I do?

regards,

Guoqi Zheng
http://www.ureader.com
 
D

Dave Fancher

Notice that each named item in the enumeration is not enclosed in quotes.
Enumerated names are not strings; they're actually constants. If you look
at the IL of an enumeration, you'll see that your Enum is actually a class
that derives from System.Enum. Each name in the Enum becomes a Public Const
field of the class.

Because the names are not strings, the dash is interpreted as a minus sign
which is an illegal character in a type or variable name.

HTH
 
P

Peter Rilling

Basically, each enum value must follow the same naming constraints that any
varaible (symbol) would have.
 
G

guoqi

Thanks for all your replies, problem sloved now. it is better to use a class
in this situation.
 
D

Dave Fancher

Enumerations really boil down to syntactical convenience. Have you
considered using a Hashtable instead?

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,588
Members
45,093
Latest member
Vinaykumarnevatia00

Latest Threads

Top