المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : foreach simple question



C# Programming
09-18-2009, 10:31 AM
I have not used foreach before but I know that the foreach method in what I am trying to do will simplify things emensely. I can adapt after I can see a example.

What I want to do is this:

I have an List of 10 objects so lets call List MyList

foreach (int i = in MyList.count)
{
Messagebox(Mylist[i])
}


So in the above example It would output 1,3,5,7,9. How would I do this?
Another side point if foreach work not like the above example but like how my other theory is All the ODD number increments will contain "%" the percent sign. But the even values will contain only letters a-z and 0-9.


I don't want to have to do it the way I know how which is double incrementing...
For (i = 0; i < MyList.count; i++)
{
do work
i++
}