Question

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
}
Was it helpful?

Solution

Prefixing reserved words in C# is done with @.

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

OTHER TIPS

You will need to prefix them with the @ symbol to use them. Here is the msdn page that explains it.

It does seem like a bad idea though - like setting FIVE to equal 6.

Why not just use a predetermined prefix so that te names are unique and future maintainers of your code understand what you are doing?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top