我有两个arrays
:
var students = new [] {"Elisa" ,"Sarah", "Frank","Frederic"};
var votes = new[] {90, 70, 40,80};
如果可能,如何使用linq
打印这样的内容?
"Elisa 90"
"Sarah 70"
"Frank 40"
"Frederic 80"
答案 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.