I'm looking a way to insert arraylist in two different arraylist with same number of items.
for an example:
I have ArrayList something like this
ArrayList mainArrayList = new ArrayList {1, 2, 3,4,5,6};
So what I want from mainArrayList to insert into two arraylist (arraylist1 and arraylist 2)
this is what i am looking to have in two arraylist:
ArrayList arrayList1 = new ArrayList {1, 2, 3};
ArrayList arrayList2 = new ArrayList {4, 5, 6};
I can do through for loop but i am sure there is better of doing this.
for (int i = 0; i < mainArrayList.Count; i++)
{
if(arraylist1.Count <3) {
arrayList1.Add(mainArrayList[i]);
}
if(arrayList1.Count >3)
{
arrayList2.Add(mainArrayList[i]);
}
}
ArrayList, useList<T>, whereTis the type to store (in this caseint.) Once you do that, you can use the LINQConcat()method to get what you want:mainList = firstList.Concat(secondList).ToList();