Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / C#
Tip/Trick

Convert ArrayList to a Generic List

Rate me:
Please Sign up or sign in to vote.
4.71/5 (7 votes)
24 Mar 2010CPOL 48.5K   10   2
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?

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Vizrt Bangladesh
Bangladesh Bangladesh
I am truly versatile and 360 degree Engineer having wide range of development experience in .NET and Java Platform. I am also proficient in system level programming in C++. To me technology is not at all a problem, it’s the client requirement that matters! That is I am ready and comfortable to use any technology to make the business of my client a success.

In my five years of experience I have the opportunities to work for fortune 500 companies of US and many renowned clients from Europe.

My Linkedin Profile: http://bd.linkedin.com/in/mahmudazad

Comments and Discussions

 
GeneralMy vote of 5 Pin
S. M. Quamruzzaman Rahmani31-May-14 21:41
S. M. Quamruzzaman Rahmani31-May-14 21:41 
GeneralMy vote of 5 Pin
Md. Rashidul Hasan Masum11-Jan-13 20:10
professionalMd. Rashidul Hasan Masum11-Jan-13 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.