jonovate Posted November 21, 2004 Share Posted November 21, 2004 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 More sharing options...
0 Winston Posted November 21, 2004 Share Posted November 21, 2004 Well it wouldn't make much sense, think about it an Enum would just be like declaring a list of variables, i'm pretty sure naming conventions of variables would also apply to Enums, like you can't declare a variable with spaces in it. Link to comment https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/#findComment-584958697 Share on other sites More sharing options...
0 jonovate Posted November 21, 2004 Author Share Posted November 21, 2004 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? Link to comment https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/#findComment-584958945 Share on other sites More sharing options...
0 Winston Posted November 21, 2004 Share Posted November 21, 2004 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. Link to comment https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/#findComment-584960182 Share on other sites More sharing options...
0 John Veteran Posted November 21, 2004 Veteran Share Posted November 21, 2004 JJ6829 said: 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] Can you rephrase that? :blink: Link to comment https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/#findComment-584960183 Share on other sites More sharing options...
0 smurfiness Posted November 21, 2004 Share Posted November 21, 2004 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"] Link to comment https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/#findComment-584961180 Share on other sites More sharing options...
0 jonovate Posted November 21, 2004 Author Share Posted November 21, 2004 Well i finished it off without using anything, just cheated kinda by using what I had already. thx all. Link to comment https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/#findComment-584963246 Share on other sites More sharing options...
0 Winston Posted November 22, 2004 Share Posted November 22, 2004 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 Link to comment https://www.neowin.net/forum/topic/246859-c-enum-with-spaces/#findComment-584964386 Share on other sites More sharing options...
Question
jonovate
Has anyone ever been able to get an enum to compile with one of its values having a space in it?
ie:
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