繁体   English   中英

如何选择集合列表中可用的子集合

[英]How to select a sub collection available in a list of collection

以下是我的班级结构

   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

提前致谢。

使用SelectMany获取所有位置并使用Distinct使它们区别开来:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM