Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

enum variable as 0 indexed matrix

Posted on 2010-01-05
4
Medium Priority
?
238 Views
Last Modified: 2012-05-08
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


0
Comment
Question by:panJacek
  • 2
4 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 26185730
declare enumaration as

enum Jack
{
jack1,
jack2
}


0
 

Author Comment

by:panJacek
ID: 26185845
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?



0
 
LVL 26

Accepted Solution

by:
tigin44 earned 2000 total points
ID: 26186018
use the casting as below

Jack jack = (Jack)1;
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26186163
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);
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question