ali
ali

Reputation: 29

Filter a List with linq

Can any one help me with this function that filter elements

Public Sub adjectAllNormals()

    Dim qry As LinkedList(Of CElement) = From elm In Elements
              From id In SelectIDs()
              Where elm.ID = id

    Console.WriteLine(qry.Count)
End Sub

Upvotes: 1

Views: 1860

Answers (2)

Cetin Basoz
Cetin Basoz

Reputation: 23797

Dim ids = SelectIDs().ToList()
Dim qry = From elm In Elements Where ids.Contains(elm.ID) select elm

Upvotes: 0

Thomas Levesque
Thomas Levesque

Reputation: 292365

A Linq query returns an IEnumerable(Of T), not a LinkedList(Of T)... You can try that instead:

Public Sub adjectAllNormals()

    Dim qry As IEnumerable(Of CElement) = From elm In Elements
              From id In SelectIDs()
              Where elm.ID = id
              Select elm

    Dim list As New LinkedList(Of CElement)(qry)
    Console.WriteLine(list.Count)
End Sub

Upvotes: 1

Related Questions