【发布时间】:2013-06-16 00:50:12
【问题描述】:
我想按属性值将我的数据拆分为列表,并检查列表项之间的所有组合选项。 我的问题是我不知道我会得到多少列表,以及除此之外是否有更好的方法:
var a = Data.Descendants("value").Where(x => x.Attribute("v").Value == "1").ToList(); var b = Data.Descendants("value").Where(x => x.Attribute("v").Value == "2").ToList(); var c = Data.Descendants("value").Where(x => x.Attribute("v").Value == "3").ToList();
foreach (var tempA in a) { foreach (var tempB in b) { foreach(c 中的 var tempC) { 做一点事; } } }
编辑:
我想从一个数据源 (var items = new List<string>{"1","1","2","3","2","1","3","3","2"}) 检查我的项目
现在我想将此列表拆分为 3 个列表 (list a = "1","1","1" - list b = "2","2","2" - list c = "3","3","3")
在这一步中,我要做的是检查从一个列表中的一项到其他列表中的其他项的所有组合。
a[0] with b[0] c[0]
a[0] with b[0] c[1]
a[0] with b[0] c[2]
a[0] with b[1] c[0]
.
.
b[1] with a[2] c[2]
.
.
谢谢!
【问题讨论】:
标签: c# list foreach combinations