Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#3.5

Converting/Changing Types of Generic List

3.00/5 (3 votes)
24 Mar 2010CPOL 1  
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)