Lets say I wanted to get each element from an ArrayList, how could that be done.
Im trying to use a for loop, but I cannot figure out how to get the element out of the ArrayList.
Lets say I wanted to get each element from an ArrayList, how could that be done.
Im trying to use a for loop, but I cannot figure out how to get the element out of the ArrayList.
I think http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsarraylistclassitemtopic.asp
see the "Item" property.
is what you need. MSDN is really good to explore and get familiar with most classes.
Originally Posted by Salem
If you know that all the elements are of the same type in the array list and you know what that type is then you could use the foreach keyword.
Example:
LTCode://ArrayList contains Control objects foreach (Control c in myArrayList) {c.Visible = false;}
Actually, you don't even need to know this at compile time
Code://ArrayList contains Control objects foreach ( object o in myArrayList ) { MessageBox.Show( o.ToString() ); }
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
Well, you do have to know the type if you want to do anything with it other than call ToString() and the other methods offered by System.Object.
LT