|
-
Aug 5th, 2005, 07:23 AM
#1
Thread Starter
Hyperactive Member
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
Last edited by Sgt-Peppa; Aug 5th, 2005 at 08:01 AM.
Reason: SOLVED
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Aug 5th, 2005, 07:27 AM
#2
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?
- ØØ -
-
Aug 5th, 2005, 07:52 AM
#3
Thread Starter
Hyperactive Member
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?
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Aug 5th, 2005, 07:58 AM
#4
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.
- ØØ -
-
Aug 5th, 2005, 08:00 AM
#5
Thread Starter
Hyperactive Member
Re: Using Numbers in an Enum
Yeah, that sound good, thanks for the help. Thats what I was looking for.
Thanks again,
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Aug 5th, 2005, 09:51 AM
#6
Re: Using Numbers in an Enum **SOLVED**
Any time for you Stephan..
- ØØ -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|