65.9K
CodeProject is changing. Read more.
Home

Convert ArrayList to a Generic List

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.71/5 (7 votes)

Mar 25, 2010

CPOL
viewsIcon

48891

There is a short cut way to convert ArrayList to a generic list instead of looping through items.Generally this is what people do :omg: List orders = new List(myArrayList.count); foreach (WarriorTrading.Order order in myArrayList) { orders.add(order); }But this...

There is a short cut way to convert ArrayList to a generic list instead of looping through items. Generally this is what people do :omg:
List orders = new List(myArrayList.count);  
 
foreach (WarriorTrading.Order order in myArrayList)  
{  
     orders.add(order);  
}
But this can be done in single line by this :-\
(myArrayList.ToArray() as WarriorTrading.Order[]).ToList();
Very simple! Isn't it?