【问题标题】:How to select a sub collection available in a list of collection如何选择集合列表中可用的子集合
【发布时间】:2013-09-10 11:55:24
【问题描述】:

以下是我的类结构

   public class ProductInfo
         Dim productName As string 
      Dim productCode As string 
      Dim Locations As List(of String)
   End Class

获取产品列表

Dim listProd As List(of ProductInfo)= entityProvider.GetProducts();

我的收藏包含 50 种产品,每种产品都有一定数量的位置。如何使用 Linq 查询此集合以获取不同的子集合(所有产品均为 Locations,但不同。因为可以在同一位置看到 2 个产品)

我正在使用 .NET 3.5 CE

提前致谢。

【问题讨论】:

    标签: .net vb.net linq .net-3.5 windows-ce


    【解决方案1】:

    使用SelectMany 获取所有位置,使用Distinct 使它们不同:

    Dim distinctLocations = entityProvider.GetProducts().
        SelectMany(Function(p) p.Locations).
        Distinct()
    

    【讨论】:

      猜你喜欢
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多