There is a array list that contain generic lists. How can i access the variables that in generic list? But i want to access the variables via the array list.
ArrayList TheList = new ArrayList();
List<NewType>[] GenericLists = new List<NewType>[4];
GenericLists[0].Add(variable);
.
.
.
for (int i = 0; i < 4; i++)
{
TheList.Add(GenericLists[i]);
}
How can i print the variables via the Array list?
You need to iterate over the items of your
ArrayList
and cast each item toList<NewType>
then you can iterate over the items in the lists and display them or whatever you want...Or you can use Linq methods to cast them:
These assumes that all items in the array list are of type
NewList
. Otherwise you will get anInvalidCastException
at runtime. To avoid this you can useis
oras
operators to check if the type isNewList
, or you can useOfType
method which does this for you: