tags:

views:

416

answers:

2

Is thre any way to have an enum entry with a hyphen, "-", in the name, for example:

enum myEnum
{
   ok,
   not-ok,
}

I've seen the question about enums having friendly names however it would save me a bit of work if I can use a hyphen directly.

Update: The reason I want to use a hyphen is it makes it easy to use an enum for lists of set values which I have no control over such as:

 rejected
 replaced
 local-bye
 remote-bye
+12  A: 

No, a hyphen is not allowed.

Identifiers

You could obviously replace the hyphen with an underscore, but as @benPearce suggested, CamelCase would be a better choice, and in line with most C# coding standards.

Mitch Wheat
I'd actually just been looking over that page. I don't knwo why they couldn't just put _ instead of Pc and a reference to the unicode doc.
sipwiz
I still can't find the official definition of "connector punctuations"
Greg
+7  A: 

Suppose you have:

enum E { a = 100 , a-b = 200 };
...

E b = E.a;
int c = (int)(E.a-b);

Is c set to 200, or 0 ?

Allowing hyphens in identifiers would make the language almost impossible to analyze lexically. This language is already hard enough to analyze what with << and >> each having two completely different meanings; we don't want to make it harder on ourselves.

The naming guidelines say to use CamelCasing for enum values; follow the guidelines.

Eric Lippert
I'd happily follow the guidelines but the string list the enum is needed to represent is out of my control. Lexical analysis may be hard getting half a dozen RFC's to remove hyphenated words is not easy either.
sipwiz