Reputation: 33
I have two arrays
:
var students = new [] {"Elisa" ,"Sarah", "Frank","Frederic"};
var votes = new[] {90, 70, 40,80};
How can I print something like this using linq
if possible?
"Elisa 90"
"Sarah 70"
"Frank 40"
"Frederic 80"
Upvotes: 3
Views: 1355
Reputation: 13755
You can use 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);
from MSDN
Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
Upvotes: 10