how do I create an enum with a name that happens to be a c# keyword?
Posted by: usmanahmad on: August 1, 2006
In VB.net; you use brackets to delimit the word.
Public
Enum test
[Public]
[Private]
End Enum
SubMain()
Dime As test = test.Private
EndSub
Such things are called Escaped Identifiers, and the equivalent in c# is the @ character.
public
enum test {
@public,
@private
}
static
void main() {
test e = test.@private;
}
They do work the same, but they don’t look the same. In c#, you have to type the unwanted escaped identifier every time you use the enum, and the enum even shows up with the @ prefix in intellisense. However, if you echo back the enum value, it will be “private”, and not “@private”, as expected.