Results 1 to 6 of 6

Thread: Using Numbers in an Enum **SOLVED**

  1. #1

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    Resolved 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

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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?


    - ØØ -

  3. #3

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    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

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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.


    - ØØ -

  5. #5

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    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

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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
  •  



Click Here to Expand Forum to Full Width