![]() |
| | #1 |
| Registered User Join Date: May 2004
Posts: 215
| Getting an element from an ArrayList Im trying to use a for loop, but I cannot figure out how to get the element out of the ArrayList. |
| osal is offline | |
| | #2 | |
| and the Hat of Clumsiness Join Date: Oct 2002
Posts: 1,101
| 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.
__________________ Quote:
| |
| GanglyLamb is offline | |
| | #3 |
| Registered User Join Date: Jan 2004
Posts: 37
| 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: Code: //ArrayList contains Control objects
foreach (Control c in myArrayList)
{ |
| CompURocket is offline | |
| | #4 |
| the hat of redundancy hat Join Date: Aug 2001 Location: Hannover, Germany
Posts: 2,769
| 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. |
| nvoigt is offline | |
| | #5 |
| Registered User Join Date: Jan 2004
Posts: 37
| 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 |
| CompURocket is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ArrayList Basics - Example | wbeasl | C# Programming | 2 | 12-26-2008 04:41 PM |
| Exercise asks me to use a subarray. What is a subarray? | yougene | C Programming | 4 | 01-05-2008 11:30 PM |
| Modify an single passed array element | swgh | C Programming | 3 | 08-04-2007 08:58 AM |
| Sorting a 2-dimensional array | kmoyle73 | C++ Programming | 3 | 05-05-2004 01:54 PM |
| Struct *** initialization | Saravanan | C Programming | 20 | 10-09-2003 12:04 PM |