troubleshooting Question

foreach C# syntax problem

Avatar of codefinger
codefingerFlag for United States of America asked on
C#Visual C++.NET
3 Comments1 Solution564 ViewsLast Modified:
private void button1_Click(object sender, EventArgs e)
        {
            string str_msg;
            str_msg = "Hello World!";
            int intger,x;
            List<int> lstints;
            lstints = new List<int>();
            intger = 1;
            
            for(x = 0;x <=5;x+=1){
                lstints.Add(intger);
                str_msg = "The current value of x is " + x.ToString();
                MessageBox.Show(str_msg);
            }

            foreach(int x_intger in lstints){

                MessageBox.Show(x_intger.ToString());
            
            }


Experienced with VB.NET, but all the jobs are asking for C#, so trying to learn it now using VS 2010 Express.  The above does not do quite what I expected  -- the second loop just shows a "1" five times, should have been 1,2,3, etc....

What did I do wrong?
ASKER CERTIFIED SOLUTION
mccarl
IT Business Systems Analyst / Software Developer
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros