Avinash Karat Avinash Karat - 1 year ago 80
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 Source

Try using Zip:

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

Console.Write(string.Join(" ", result));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download