使用linq筛选List



谁能帮我一下这个过滤元素的函数

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

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
Dim ids = SelectIDs().ToList()
Dim qry = From elm In Elements Where ids.Contains(elm.ID) select elm

相关内容

  • 没有找到相关文章