Convert from IEnumerable<gobject> to IEnumerable<x>

The easiest way to convert from IEnumerable<object> to a specific class e.g. IEnumerable<DomainObject> is by using the LINQ extension method Cast<T>.

IEnumerable<object> objEnum = GetData();
IEnumerable<DomainObject> domainObjEnum = objEnum.Cast<DomainObject>().ToList();


The same process can be used in reverse.

No comments:

Post a Comment