panJacek
asked on
enum variable as 0 indexed matrix
Hello experts :-)
Another newbie question if I may :-)
My variable:
enum Jack
{
int jack1,
int jack2
}
Jack jack = [item with index 1, which is jack2]
Question:
How can I do it?
Thank you
panJacek
Another newbie question if I may :-)
My variable:
enum Jack
{
int jack1,
int jack2
}
Jack jack = [item with index 1, which is jack2]
Question:
How can I do it?
Thank you
panJacek
ASKER
Sorry, my mistake.
The same question one more time:
My variable:
enum Jack
{
jack1,
jack2
}
Jack jack = [item with index 1, which is jack2 but I want to use integer index not 'jack2' index]
Question:
How can I do it?
The same question one more time:
My variable:
enum Jack
{
jack1,
jack2
}
Jack jack = [item with index 1, which is jack2 but I want to use integer index not 'jack2' index]
Question:
How can I do it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you want "jack" to have a VALUE of 1?...or be assigned to the SECOND entry in the Enum?
Since you could have this:
enum Jack
{
jack1 = 8,
jack2 = 16
}
It would be "legal" to assign a value of 1 even though there isn't a corresponding entry that equals 1:
Jack jack = (Jack)1; // works even though Jack doesn't have an entry with 1!
If you want the second entry, then you could do:
String[] names = Enum.GetNames(typeof(Jack) );
Jack jack = (Jack)Enum.Parse(typeof(Ja ck), names[1]);
string msg = "jack = " + jack.ToString() + " = " + ((int)jack).ToString();
MessageBox.Show(msg);
Since you could have this:
enum Jack
{
jack1 = 8,
jack2 = 16
}
It would be "legal" to assign a value of 1 even though there isn't a corresponding entry that equals 1:
Jack jack = (Jack)1; // works even though Jack doesn't have an entry with 1!
If you want the second entry, then you could do:
String[] names = Enum.GetNames(typeof(Jack)
Jack jack = (Jack)Enum.Parse(typeof(Ja
string msg = "jack = " + jack.ToString() + " = " + ((int)jack).ToString();
MessageBox.Show(msg);
enum Jack
{
jack1,
jack2
}