class A {}
class B : A {}
class C : A {}
ICollection<A> myCollection;
var myresults = myCollection.Where(item => item.GetType() is C);
Given the hierarchy above the where predicate effectively does nothing.
How can I structure the where predicate to return all items of type C from the collection?
而不是在哪里可以使用OfType<TResult>
var myresults = myCollection.OfType<C>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.