• 0

[C#] Enum with spaces?


Question

Has anyone ever been able to get an enum to compile with one of its values having a space in it?

ie:

private enum iTest
  {
 	 Food, Keys, Wife, Bath And Shower
  };

I have tried with single quotes, double quotes, parantheses, and square brackets around the value, and stilll no luck.

projects\consoleapplication1\class1.cs(12,27): error CS1513: } expected

projects\consoleapplication1\class1.cs(12,37): error CS1002: ; expected

projects\consoleapplication1\class1.cs(19,10): error CS1518: Expected class,

projects\consoleapplication1\class1.cs(19,27): error CS1001: Identifier expected

projects\consoleapplication1\class1.cs(19,29): error CS1518: Expected class, delegate, enum, interface, or struct

projects\consoleapplication1\class1.cs(26,1): error CS1022: Type or namespace definition, or end-of-file expected

(using VS.NET 2003 to compile)

Link to comment
https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/
Share on other sites

7 answers to this question

Recommended Posts

  • 0
  JJ6829 said:
Yah alright, makes sense now that I think about it.

What would be the easiest collection to iterate through, where I can refer to either an index or through teh value name?  ArrayList?

584958945[/snapback]

If you want to access elements through a value name, probably have a look at HashMaps.

  • 0
  Winston said:
If you want to access elements through a value name, probably have a look at HashMaps.

584960182[/snapback]

The type in C# is called Hashtable, and that's exactly what it does. You can iterate through the collection to get what you want (the index approach) or you can refer to elements by names (if the keys are strings):

myHashList["Item1"]

  • 0
  dannysmurf said:
The type in C# is called Hashtable, and that's exactly what it does. You can iterate through the collection to get what you want (the index approach) or you can refer to elements by names (if the keys are strings):

myHashList["Item1"]

584961180[/snapback]

lol :p... yeah i'm thinking in terms of Java too much

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.