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"
我有兩個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"
您可以使用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.
這是快...'+ 1' – 2014-09-28 12:09:32
感謝你,因爲太容易 – dav 2014-09-28 12:16:04