使用linq过滤列表

时间:2011-05-03 10:03:16

标签: vb.net linq

任何人都可以帮助我使用这个过滤元素的功能

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

2 个答案:

答案 0 :(得分:1)

Linq查询返回IEnumerable(Of T),而不是LinkedList(Of T) ...您可以尝试这样做:

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

答案 1 :(得分:0)

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