【发布时间】:2014-09-28 12:07:32
【问题描述】:
我有两个arrays:
var students = new [] {"Elisa" ,"Sarah", "Frank","Frederic"};
var votes = new[] {90, 70, 40,80};
如果可能,我如何使用linq 打印这样的内容?
"Elisa 90"
"Sarah 70"
"Frank 40"
"Frederic 80"
【问题讨论】:
我有两个arrays:
var students = new [] {"Elisa" ,"Sarah", "Frank","Frederic"};
var votes = new[] {90, 70, 40,80};
如果可能,我如何使用linq 打印这样的内容?
"Elisa 90"
"Sarah 70"
"Frank 40"
"Frederic 80"
【问题讨论】:
你可以使用Linq.Zip
var students = new[] { "Elisa", "Sarah", "Frank", "Frederic" };
var votes = new[] { 90, 70, 40, 80 };
var studendsAndVotes = students.Zip(votes, (student, vote) => student + " " + vote);
来自 MSDNApplies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
【讨论】: