Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Convert ArrayList to a Generic List

, 23 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
You can filter all elements of arrayList that can be cast to the same type using Enumerable.OfType(Of TResult) Method[^]. List typedList = arrayList.OfType().ToList();
You can filter all elements of arrayList that can be cast to the same type using Enumerable.OfType(Of TResult) Method[^].

List<myclass> typedList = arrayList.OfType<myclass>().ToList();

License

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

Share

About the Author

Michael Freidgeim
Software Developer (Senior)
Australia Australia
No Biography provided

Comments and Discussions

 
QuestionFine! PinmemberVolynsky Alex22-May-12 1:18 
GeneralOr, if you're certain that all the elements are of the corre... PinmemberMember 360013614-Nov-11 18:49 
Generalasfsfsfs PinmemberMember 360013614-Nov-11 18:45 
Generaldadadadada PinmemberMember 360013614-Nov-11 18:45 
GeneralOr, if you're certain that all the elements are of the corre... PinmemberRichard Deeming24-Oct-11 8:16 
Or, if you're certain that all the elements are of the correct type (or want an exception if they're not), use the Cast method:
 
typedList = arrayList.Cast<MyClass>().ToList();

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 23 Oct 2011
Article Copyright 2011 by Michael Freidgeim
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid