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: 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: 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)
  • Re: mutually referential (Pg 140 K&R2)
    ... >> Forward declared struct and union tags are incomplete, ... You can't forward declare an enum ... the values of all the members of the enumeration. ...
    (comp.lang.c)
  • Re: Enum question...
    ... You can declare an enumeration at the namespace level, ... Public Enum icPriority As Integer ... Public Sub DoCheck' This ... How do I reference the global enum in a procedure as an parameter? ...
    (microsoft.public.dotnet.general)