Life Beyond Code

how do I create an enum with a name that happens to be a c# keyword?

Posted 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.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Calendar

August 2006
M T W T F S S
« Jul   Sep »
 123456
78910111213
14151617181920
21222324252627
28293031  

My del.icio.us

RSS Readings

  • An error has occurred; the feed is probably down. Try again later.

And Here is ME...

Sand Play - at Budva Beach (Montenegro)

My friends - Salman, Michal, Imre

Teradata Team Dinner, ProMonte Project, Montenegro (Imre, Viladimir, Danial)

More Photos

Top Clicks

  • None
%d bloggers like this: