Avinash Karat Avinash Karat - 1 month ago 6
C# Question

Pair values from two lists

I have two lists with me as per the following example.

List<string> words = new List<string>() {"V","H","M" };

List<int> numbers = new List<int>() {10,20,30 };


I need to pair the values of these two lists so that my output needs to be exactly like the following text.

Desired output :
V10 H20 M30

Answer

Try using Zip:

var result = words
  .Zip(numbers, (w, n) => $"{w}{n}");

Console.Write(string.Join(" ", result));