Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

constant array with enum as "iterator"

Status
Not open for further replies.

kittyyo

Programmer
Oct 17, 2001
89
AT
Hi there,

I'd like to know if the following is possilbe in C#:

Consider the enum "DayOfWeek" which is already built into the .NET framework.
I'd like to create a constant one-dimensional array whose elements should be addressable by the DayOfWeek enum, for example (pseudo-code!)

Code:
const byte[DayOfWeek] MY_ARRAY = {5, 2, 6, 3, 6, 2, 1};

such that I could access the byte value "3" by
Code:
MY_ARRAY[Wednesday]

Thanks a lot for any suggestions,
Anne
 
Cast the enum to an int, so that the indexer will understand it.
Code:
MyArray[(int)DayOfWeek.Wednesday]
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top