Using C# keywords in your Enums

Sometimes you want to define a value in your enumeration which has the same name as a keyword in C#.

The compiler will not like this:

The solution in C# for this is to prefix your value with the @-character:

namespace EnumTest
{
 //as = attosecond
 public enum Time : byte
 {
 s = 1,
 ms = 2,
 @as = 3
 }
}

For Visual Basic use square brackets like this [as].

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s