gpt4 book ai didi

c# - 在 C# 中对 n 个列表的所有列表项选项进行操作

转载 作者:太空宇宙 更新时间:2023-11-03 16:11:43 25 4
gpt4 key购买 nike

我想按属性值将我的数据拆分为列表,并检查列表项之间的所有组合选项。我的问题是我不知道我会得到多少列表,以及除了这种方式之外是否还有更好的方法:

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(a 中的 var tempA){ foreach(b 中的 var tempB) { 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]
.
.

谢谢!

最佳答案

您可以尝试使用 LINQ GroupBy 方法吗?这里有一些例子:

LINQ GroupBy examples

关于c# - 在 C# 中对 n 个列表的所有列表项选项进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17192040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com