使用LinQ合并两个数组

时间:2014-09-28 12:07:32

标签: c# arrays linq

我有两个arrays

var students  = new [] {"Elisa" ,"Sarah", "Frank","Frederic"};

var votes  = new[] {90, 70, 40,80};

如果可能,如何使用linq打印这样的内容?

"Elisa 90"
"Sarah 70" 
"Frank 40"
"Frederic 80"

1 个答案:

答案 0 :(得分:9)

您可以使用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);  
来自MSDN的


Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.