Link to home
Start Free TrialLog in
Avatar of panJacek
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


Avatar of tigin44
tigin44
Flag of Türkiye image

declare enumaration as

enum Jack
{
jack1,
jack2
}


Avatar of panJacek
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?



ASKER CERTIFIED SOLUTION
Avatar of tigin44
tigin44
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Tomlinson
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(Jack), names[1]);
            string msg = "jack = " + jack.ToString() + " = " + ((int)jack).ToString();
            MessageBox.Show(msg);