- Home /
Question by
Bonifatius GK · Nov 27, 2012 at 08:11 AM ·
c#collections
Access Array inside ArrayList()
hi, i have a problem to access an Array insede an ArrayList, in this the code(c#) :
public void getWaypoints() {
ArrayList potentialWPs = new ArrayList();
potentialWPs.Add(containerWaypoint.GetComponentInChildren(typeof(Transform)));
wayPoints = new ArrayList();
foreach (Transform potentialWP in potentialWPs){
if(potentialWP.transform != containerWaypoint.transform){
wayPoints[wayPoints.Count] = new ArrayList(2);
wayPoints[wayPoints.Count][0] = potentialWP;
}
}
i want to access the array inseide each ArrayList's elements, but its says that "cannot aplly indexing with[] to an expression of type 'object'" to line "wayPoints[wayPoints.Count][0]", anyone knows how to solve it..??
thanks for the help n sorry for my bad english....
Comment
Answer by Paulius-Liekis · Nov 27, 2012 at 11:15 AM
Change
wayPoints[wayPoints.Count][0] = potentialWP;
to
((ArrayList)wayPoints[wayPoints.Count])[0] = potentialWP;
or simply use generics.
yes, i've tried that solution, but then i'd prefer to use struct for a better array management.. thx for the answer btw....