Re: Custom values in Enum



Of course, just assign each value explicitly:

public enum Days {Sat=1,Sun=2,Mon=12,Tue=13,Wed=14}

If I recall correctly the following will work too, as subsequent values are sequential:

public enum Days {Sat=1,Sun,Mon=12,Tue,Wed}

This is one of those "check the docs" and/or "try it and see" kinds of issues, you could answer the question in about 60 seconds that way.

Incidentally I would not take pains to make it a byte enum unless you expect to store large amounts of the values in memory or something. Generally, ints are handled more efficiently. The only reason to use byte or short in or out of an enum is if you are going to hold a big collection or matrix of them and you want to relieve memory pressure. The system architecture is generally most efficient in terms of access speed, with ints.

Best,

--Bob

Vi wrote:
Hi,
Is there a way to declare an Enum with non-secventual values? For example I want to declare the following enum:
public enum Days :byte {Sat=1, Sun, Mon, Tue, Wed};


where Sat=1, Sun=2, Mon=12, Tue=13, Wed=14}

Is this possible?
Thanks

.



Relevant Pages

  • Re: Enumerated types
    ... Enum ACGroup ... I cannot then access the members of the group. ... One alternative I could try, in the mean time, is to declare a string array ...
    (microsoft.public.access.formscoding)
  • Re: non-static method gotcha
    ... the declared enum, 'SubmissionSite' in your example. ... Its effect is to declare that C is not an inner class. ... extends the immediately enclosing enum type. ... decompiled anonymous class. ...
    (comp.lang.java.help)
  • Re: Newbie Question
    ... It may be a problem but the compiler error clearly stated that he tried to ... declare a method where only a class, delegate, enum, interface, or struct is ... >> public static extern int SendCharFmtMsg(IntPtr hWnd, int Msg, int ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: stratgies for organizing elements in a passed array
    ... enumeration is nothing except a special syntax to declare a set of named ... You don't need f2003 to declare a set of named constants. ... to have symbolic names for the various keywords. ... I use an old preprocessor to get the equivalent of an enum. ...
    (comp.lang.fortran)
  • Re: enum safety
    ... 'Although variables of enum types may be declared, ... you declare declare a valid ... A C enumerated type doesn't act like an enumerated type in, say, ...
    (comp.lang.c)