【问题标题】:Using method FindAll in two generic lists在两个通用列表中使用方法 FindAll
【发布时间】:2015-05-21 21:25:31
【问题描述】:

我在 vb.net 程序中有两个通用列表。我想循环 List_A 并在 List_B 中搜索 List_A.ID,共同的元素应该存储在第三个列表 (LIST) 中。

For Each n As BE_Busq In List_A

    LIST = List_B.FindAll(Function(x As BE_Busq) x.ID = n.ID)
    '' for each step, LIST should be incremented, not be replaced
Next

方法 FindAll 将返回一个通用列表。如何为循环中的每一步增加 LIST 而不是替换它?

【问题讨论】:

    标签: vb.net generic-list findall


    【解决方案1】:

    试试这个:

    LIST.addrange(List_B.FindAll(Function(x As BE_Busq) x.ID = n.ID))
    

    【讨论】:

      【解决方案2】:

      您可以使用AddRange 方法将多个项目添加到列表中。

      For Each n As BE_Busq In List_A
          LIST.AddRange(List_B.FindAll(Function(x As BE_Busq) x.ID = n.ID))
      Next
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多