2014-09-28 102 views
2

我有两个arrays合并两个数组使用LINQ

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

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

如何打印像这样使用linq如果可能的话?

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

回答

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.

+2

这是快...'+ 1' – 2014-09-28 12:09:32

+0

感谢你,因为太容易 – dav 2014-09-28 12:16:04