Converting/Changing Types of Generic List





3.00/5 (3 votes)
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!!!