Using Numbers in an Enum **SOLVED**
Hey all, I am trying to use Numbers in my Enum, but I get an Error.
Code:
public enum myCode{100,200,300,....}
If I write plain text it works
Code:
public enum myCode{one,two,three,....}
Error says: Identifier expected!
Can anyone explain?
Thanks,
Stephan
Re: Using Numbers in an Enum
Why whould you need numbers? An enum is used to give numbers a name, not to give numbers a new value?
What are you trying to do? do you know what an enum is?
- ØØ -
Re: Using Numbers in an Enum
I have a couple of errorcodes that I want to provide for my Exception class! For example 100 = UserException.
So in the end I want to do something like this:
Code:
throw new CustomException(myCode.100);
What would be the best approach for something like that?
Re: Using Numbers in an Enum
Isn't it easier to just remember the name then the error code anyway. So you can have an Enum like this:
Code:
enum myCode : int {
UserException = 100,
NoteMeException, //This will imply 101 as the number for this string
}
Then you can do:
Code:
throw new CustomException((int)myCode.UserException);
You are then throwing an int, and the value of that int is 100.
- ØØ -
Re: Using Numbers in an Enum
Yeah, that sound good, thanks for the help. Thats what I was looking for.
Thanks again,
Stephan
Re: Using Numbers in an Enum **SOLVED**
Any time for you Stephan..:)
- ØØ -