AsValeO
AsValeO

Reputation: 3039

LINQ Select from two Collections with same length

var listA = new List<string> {"One", "Two", "Three"};
var listB = new List<int> {1, 2, 3};
var listC = new List<Tuple<string, int>>();

Here I've got two Lists with the same length. Is there a way to fill third listC with LINQ?

"One", 1
"Two", 2
"Three", 3

Upvotes: 1

Views: 244

Answers (1)

ocuenca
ocuenca

Reputation: 39326

I think you are looking the Zip extension method:

var listA = new List<string> { "One", "Two", "Three" };
var listB = new List<int> { 1, 2, 3 };
var listC = listA.Zip(listB, (s, i) => new Tuple<string, int>(s, i)).ToList();

Upvotes: 3

Related Questions