I've got a list of List<KeyValuePair<string,string>>
var results = new List <KeyValuePair<string, string>>();
I've also got two Lists of strings:
var position= new List<string>{ "first", "second", "third" };
var name = new List<string>{ "John", "Diana", "Matthew", "Lisa", "James"};
The two lists can be of a different size, just would add an empty string instead.
I want to merge them together to create a new results
. I'm currently using this:
results = position.Zip(name, (x, y) => new KeyValuePair<string, string>(x, y)).ToList();
This would work if only both lists are of the same size. However, if not, its trimming the name
list to match the position
list. So not all values are there.
I need to achieve the following
first,John
second,Diana
third, Matthew
, Lisa
, Jame
Both lists can be, at any time, of variable sizes, not fixed. So sometimes name
can be greater than position
and vice versa.
I've seen were SelectMany
is used, but not sure how to combine it to my Zip
.
Any ideas or suggestions?