Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Convert ArrayList to a Generic List

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
23 Oct 2011CPOL 26.7K   1   5
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)


Written By
Software Developer (Senior)
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionFine! Pin
Volynsky Alex22-May-12 1:18
professionalVolynsky Alex22-May-12 1:18 
GeneralOr, if you're certain that all the elements are of the corre... Pin
Member 360013614-Nov-11 18:49
Member 360013614-Nov-11 18:49 
Generalasfsfsfs Pin
Member 360013614-Nov-11 18:45
Member 360013614-Nov-11 18:45 
Generaldadadadada Pin
Member 360013614-Nov-11 18:45
Member 360013614-Nov-11 18:45 
GeneralOr, if you're certain that all the elements are of the corre... Pin
Richard Deeming24-Oct-11 8:16
mveRichard Deeming24-Oct-11 8:16 

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.