Linq Zip麻烦

时间:2018-06-17 01:59:40

标签: c# linq lambda

var zip = testNames.Zip(testNumbers, (code, state) => code + ": " + state); 

给了我一个IEnumberable字符串,我怎样才能获得IEnumberable字符串字符串?

1 个答案:

答案 0 :(得分:2)

根据你在问题中给我们的内容,你有两个选择:

var testNames = new [] { "A", "B" };
var testNumbers = new [] { 1, 2 };

var zip1 = testNames.Zip(testNumbers, (code, state) => new { code, state });

var zip2 = testNames.Zip(testNumbers, (code, state) => (code, state));

两者都是有效的C#。

根据您之前的question阅读情况,您需要了解此.Zip方案。您应该能够在单个查询中读取原始数据。我的answer向您展示了如何。