Charlie Calvert on Elvenware

Writing Code and Prose on Computers


This is what is happening:

itemNames is an array of string. We index into arrays of strings, and indeed into all arrays, with integers:

string someValue = itemNames[1];

ItemType.MinkGloves is part of an enumerated type. In particular, it is the first item in the enumerated type. If we write this, then we can convert the item from the enumerated type into an integer:

int someValue = (int)ItemType.MinkGloves;

In this case, someValue will be assigned the value 0, because MinkGloves is the first item in the type, and as is nearly always the case in C#, the first item is identified with a zero, not with a one.

Now lets combine the two things we said above:

string someValue = itemNames[(int)ItemType.MinkGloves];

This is the same thing as writing:

string someValue = itemNames[0];

Do you see?

BTW: When you declare the enumerated type, be sure to put it outside of Main().