Options for an Enum with reserved types

  • Thread starter Thread starter Ryan Taylor
  • Start date Start date
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
 
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
///
 
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
 
Back
Top