65.9K
CodeProject is changing. Read more.
Home

Converting/Changing Types of Generic List

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (3 votes)

Mar 25, 2010

CPOL
viewsIcon

9202

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!!!