Click here to Skip to main content
Click here to Skip to main content

Convert ArrayList to a Generic List

By , 23 Oct 2011
 
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)

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionFine!memberVolynsky Alex22 May '12 - 1:18 
GeneralOr, if you're certain that all the elements are of the corre...memberMember 360013614 Nov '11 - 18:49 
GeneralasfsfsfsmemberMember 360013614 Nov '11 - 18:45 
GeneraldadadadadamemberMember 360013614 Nov '11 - 18:45 
GeneralOr, if you're certain that all the elements are of the corre...memberRichard 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   

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