I have a list contains 2 different types of objects which are polylines and texts. I want to create a new list of polylines only.
what I do is;
var list2 = list1.SelectMany(x=> x.Type == PolyLine)
Error:'PolyLine' is a type, which is not valid in the given context.
How do I filter those objects here?
Simply use the OfType<T> extension:
var list2 = list1.OfType<PolyLine>().ToList();
This selects all elements in list1 that are of type PolyLine.
After ToList() the resulting type of list2 is List<PolyLine>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With