2014-09-28 64 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