Options for an Enum with reserved types

R

Ryan Taylor

Hello.

I have a quick and "simple" question that will probably boil down to opinion
more than anything else. I need a FieldType property for a class I am
writing. As such an Enum would be the perfect solution for this property. In
C# I can write

Public Enum FieldType
Integer = 0
Float
Double
String
Date
ObjectId
End Enum

And everything works like a charm. I have been requested to rewrite this in
VB.NET. However, VB.NET is not case sensitive so that structure does not
work because Interger, Double, String and Date are reserved types regardless
of case. Is there a defined recommended alternative for this? Prefix or
Suffix? What do you think about?

Public Enum FieldType
enumInteger = 0
enumFloat
enumDouble
enumString
enumDate
enumObjectId
End Enum

or

Public Enum FieldType
_Integer = 0
_Float
_Double
_String
_Date
_ObjectId
End Enum
 
H

Herfried K. Wagner [MVP]

Ryan Taylor said:
I need a FieldType property for a class I am writing. As such an Enum
would be the perfect solution for this property. In C# I can write

Public Enum FieldType
Integer = 0
Float
Double
String
Date
ObjectId
End Enum

And everything works like a charm. I have been requested to rewrite this
in VB.NET. However, VB.NET is not case sensitive so that structure does
not work because Interger, Double, String and Date are reserved types
regardless of case.

Put the keywords between square brackets to escape them:

\\\
Public Enum FieldType
[Integer] = 0
Float
[Double]
...
End Enum
///
 
C

Carlos J. Quintero [VB MVP]

You can use parenthesis and it will work:

Public Enum FieldType
[Integer] = 0
[Float]
....


--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 

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

Top