C# 如何使用Linq获取列表中项目的摘要
以上是我的课程。 假设一个产品可以在不同的货架和不同的行中找到。 此外,一行可以容纳多个产品 数据将与此类似C# 如何使用Linq获取列表中项目的摘要,c#,.net,vb.net,linq,C#,.net,Vb.net,Linq,以上是我的课程。 假设一个产品可以在不同的货架和不同的行中找到。 此外,一行可以容纳多个产品 数据将与此类似 Public Class Product public Name As String public ID as String public ShelfList as List(of Shelf) End Class Public Class Shelf public Name As String public ID as String public Row as List
Public Class Product
public Name As String
public ID as String
public ShelfList as List(of Shelf)
End Class
Public Class Shelf
public Name As String
public ID as String
public Row as List(of Row)
End Class
Public Class Row
public Name As String
public ID as String
End Class
以下是类似的数据
List(of Products) -> List(of Shelf) -> List(of Rows)
因此,从上面的产品列表中,我需要生成摘要。(行名称和每行中的项目数)
注:
我正在使用VB.NET,目标是CE3.5。C#也感谢您的建议。提前谢谢。我认为您必须更改数据结构 我会这样做 货架列表-->行列表-->产品列表 为什么产品会跟踪这一行? 它是包含不同产品的行 每个架子
选择Shelf number-->Row number-->Product name您可以嵌套LINQ查询,例如(对不起,我是C-sharp人)
虽然我忽略了第三层,但这样的事情应该做 但根据设计,这是不可能的。
Boost -> Shelf 1 -> Row 1,Row 2
Shelf 2 -> Row 2
Horlicks ->Shelf 1-> Row 1
Complain ->Shelf 2-> Row 2,Row 3
Colgate -> Shelf 2- Row 3
Shelf 1 Row 1 - 2 (Boost and horlicks)
Shelf 1 Row 2 - 1 (Boost)
Shelf 2 Row 1 - 1 (Horlicks)
Shelf 2 Row 2 - 2 (Complain and Boost)
Shelf 2 Row 3 - 1 (Colgate)
var a = from t1 in Products
select new
{
Name = t1.Name,
Summary = String.Join(", ",(from t2 in t1.ShelfList
select t2.Name))
};