我有以下问题,我想寻求帮助。我必须选择不同的值(一个属性的标准),然后从其余属性中提取不同的值。
假设我有以下课程,其中每个课程BOM都有一个或多个FlatComponents不同的Partsand QtyPer。
例子:
public sealed class BOM {
public string FlatComponent {
get;
set;
}
public string Part {
get;
set;
}
public string QtyPer {
get;
set;
}
public BOM(String flatComponent, String part, String qtyPer) {
this.FlatComponent=flatComponent;
this.Part=part;
this.QtyPer=qtyPer;
}
}
List<BOM> list=new List<BOM>();
list.Add(new BOM("a", "1", "2"));
list.Add(new BOM("a", "3", "4"));
list.Add(new BOM("b", "5", "6"));
list.Add(new BOM("c", "7", "8"));
list.Add(new BOM("c", "9", "0"));
如何FlatComponents使用 LINQ(以逗号分隔)在每个属性中选择不同的值及其不同的值?
结果 = [
["a", "1, 3", "2, 4"],
[“b”,“5”,“6”],
["c", "7, 9", "8, 0"]
]
我试过使用.Distinct(),但我对 LINQ 很陌生......