Reputation: 7102
I'm trying to write a linq query that returns all objects of a certain type.
Would something like this work if I wanted to get all the cars that are sedans?
Dim cars = From c In carFactory.GetAllcars()
Select car = carFactory.GetAuto(c.ID)
Where TypeOf (car) Is Sedan
Upvotes: 0
Views: 149
Reputation: 887469
That will work, but the return type will still be IEnumerable(Of Car)
.
Instead, you can write sequence.OfType(Of Sedan)()
; this will filter out non-sedans and return an IEnumerable(Of Sedan)
.
Upvotes: 5