Click here to Skip to main content
15,894,017 members
Articles / Programming Languages / C# 3.5
Tip/Trick

Converting/Changing Types of Generic List

Rate me:
Please Sign up or sign in to vote.
3.00/5 (3 votes)
24 Mar 2010CPOL 9.1K   2  
Suppose we have a base entity class called BaseEntity.We create a child Entity named Status inheriting BaseEntity public class Status: BaseEntityNow lets assume we have two Generic ListList mainList = new List();List childList;Now we want to...
Suppose we have a base entity class called BaseEntity.

We create a child Entity named Status inheriting BaseEntity

public class Status: BaseEntity


Now lets assume we have two Generic List

List<BaseEntity> mainList = new List<BaseEntity>();
List<Status> childList;


Now we want to convert mainList to childList and this can be converted easily by using Cast extension method that can be found under System.Linq

childList =  mainList.Cast<Status>().ToList();



Happy Conversion!!!

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

 
-- There are no messages in this forum --