如何使用子列表搜索列表 [英] How do I search a List with a Sublist
问题描述
我对VB.Net有点新,在这里遇到问题:
我有两个课程:产品和组件
产品
产品编号
mycomponentlist List(of Components)
...
组件
componentnumber
...
我现在想要搜索一个组件号
myProductlist列表(产品列表)以获取所有产品这个组件。
如果不使用几个For-Loops我怎么能这样做?
我发现的是这样的:
Dim results As List(Of Components)
results = mycomponentlist.FindAll(Function(column)column.componentnumber =123)
Hi,
I´m somewhat new to VB.Net and have a problem here:
I have two classes: Products and Components
Products
productnumber
mycomponentlist List(of Components)
...
Components
componentnumber
...
I now want to search for a componentnumber in
myProductlist List(of Products) to get all Products with this component.
How can I do this without using several For-Loops?
What i found was something like this:
Dim results As List(Of Components)
results = mycomponentlist.FindAll(Function(column) column.componentnumber= "123")
推荐答案
尝试:
Try:
Dim results = myProductList.Where(Function(pp) pp.MyComponentList.Where(Function(cc) cc.ComponentNumber = 123).Count() <> 0)
尝试使用此条件
if(ListProducts。相交(子列表).Count> 0)
try use this condition
if(ListProducts.Intersect(sublist).Count > 0)
这篇关于如何使用子列表搜索列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!