user1400915 user1400915 - 5 months ago 35
C# Question

Join two lists without having any matching columns in LINQ

I have two separate lists from db as :

List<Id> lstId
which has values

List<name> lstnaname
which has values

I want to combine these two lists which don’t have any common column .
My expected output would be

List<output> out
Out[0] = {0,”a”}
Out[1] = {1,”b”}

I tried using concat in linq but it just add the listA to listB.

Join clause doesn’t work because there are no common fields.
How would I achieve it?


Use Zip:

var result = lstId.Zip(lstName, (id, name) => new { id, name });