score:13

Accepted answer

Using LINQ, you can use Cast to cast the items, and use ToList to get a list.

Try:

 IEnumerable<object> someCollection; //Some enumerable of object.
 var list = someCollection.Cast<IFoo>().ToList();

score:4

Try this:

enumerable.Cast<IFoo>().ToList();

score:4

someCollection.Cast<IFoo>().ToList()


Related Articles