TobiasWittenburg TobiasWittenburg - 4 months ago 29
Vb.net Question

Reserved Keyword in Enumeration in C#

I would like to use

as
and
is
as members of an enumeration. I know that this is possible in VB.NET to write it like this:

Public Enum Test
[as] = 1
[is] = 2
End Enum


How do I write the equivalent statement in C#?
The following code does not compile:

public enum Test
{
as = 1,
is = 2
}

Answer

Prefixing reserved words in C# is done with @.

public enum Test
{
    @as = 1,
    @is = 2
}