Custom values in Enum

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
 
B

Bob Grommes

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top