我有三个(可能有超过3-4个通用列表,但在这个例子中让3)通用列表.
List<string> list1
List<string> list2
List<string> list3
Run Code Online (Sandbox Code Playgroud)
所有列表都具有相同数量的元素(相同的计数).
我用它来组合两个ZIP列表:
var result = list1.Zip(list2, (a, b) => new {
test1 = f,
test2 = b
}
Run Code Online (Sandbox Code Playgroud)
我用它来foreach声明,以避免foreach每个List,就像
foreach(var item in result){
Console.WriteLine(item.test1 + " " + item.test2);
}
Run Code Online (Sandbox Code Playgroud)
如何在三个列表中使用带有Zip的simmilary?
谢谢
编辑:
我想要:
List<string> list1 = new List<string>{"test", "otherTest"};
List<string> list2 = new List<string>{"item", "otherItem"};
List<string> list3 = new List<string>{"value", "otherValue"};
Run Code Online (Sandbox Code Playgroud)
ZIP之后(我不知道方法),我想结果(在VS2010调试模式下)
[0] { a = {"test"},
b = {"item"},
c = {"value"}
}
[1] { a = …Run Code Online (Sandbox Code Playgroud) c# ×1