Custom values in Enum

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top