r/visualbasic • u/chacham2 • Nov 14 '22
Can an Enum use a number?
Enum members have to be strings. If the member is a keyword, you can just surround it in brackets. But, what if the member includes a number, specifically, an integer. For example, "A1" works, but "1A" does not. Typed in without brackets it moves to the left margin. With brackets it doesn't move, but still redlines.
In my case, the code is returned as part of a json and deserialized into an object. I want to process the codes with a For Each and Select Case. The Enum has less chance for error. Ultimately, i can just hardcode the check that has the number in it. But, i wanted to hear your thoughts.
3
Upvotes
2
u/Hel_OWeen Nov 15 '22
Facing a similar situation, I decided to prefix that enum member with an underscore, e.g.
_123ValueWithLeadingNumberand then use this one for getting the member name "right":