Life Beyond Code

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.

Leave a Reply

Calendar

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

My del.icio.us

RSS Readings

  • Omni Daily News November 16, 2009
    "Besides Coca-Cola, the other thing that is universally known is cowboys and Indians." The Wall Street Journal interviews Cormac McCarthy and John Hillcoat, director of McCarthy's The Road, releasing later this month. [via Vulture, and, erm, Omni Daily News. My bad.]Unlike: The New Oxford American Dictionary has picked their newest word of the […]
    Amazon.com Bookstore
  • More on Donald Harington, from Toby Press November 16, 2009
    Amazon.com Bookstore
  • End-o'-the-Week Kid-Lit Roundup November 16, 2009
    Quick links from around the kid-lit blogosphere: "Andy Warhol, Children’s Illustrator." Educating Alice makes quite the auction find, some Andy Warhol children's book illustrations(!): Neil Gaiman interview. The author of Odd and the Frost Giants talks to School Library Journal. This being Gaiman, it's great. (E.g.: "If you wri […]
    Amazon.com Bookstore
  • More Best Books: The Atlantic's History-Heavy Top 25 November 14, 2009
    I haven't been doing as good a job as Largehearted Boy in tracking all the Best Books of 2009 lists that are coming out (although it's true that about half of his links at this early stage are to our own voluminous offerings), but I wanted to note one more list I ran across: The Atlantic's top 25 books of the year, which is, really, literary e […]
    Amazon.com Bookstore
Watch videos at Vodpod and other videos from this collection.

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