Arjang Arjang - 1 month ago 9
C# Question

LINQ query returning objects with property value of specific subtype

Suppose we have 3 interfaces

IA , IB, IC
where
IB : IA , IC : IA

And a class
TClass
with property
A
of type
IA


Let
List<TClass> objects


What is the LINQ query to get all the objects from the list that have
IB
as value of property
A
?

Answer
var ofType = objects.Where(x => x.A is IB);
Comments