1

I have two separate lists from db as :

List<Id> lstId which has values 0,1,2,…

List<name> lstnaname which has values “a”,”b”,c”

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?

user1400915
  • 1,933
  • 6
  • 29
  • 55
  • Why would you expect `{0, "a"}` rather than `{1, "a"}` for example? Are you just relying on the ordering? – Jon Skeet Aug 05 '16 at 05:01
  • Yes, its just one-to-one ordering 0th element of listA to 0th element of listB and so on.... – user1400915 Aug 05 '16 at 05:01
  • Please check this link for the help. http://stackoverflow.com/questions/10297124/how-to-combine-more-than-two-generic-lists-in-c-sharp-zip – pulkit12 Aug 05 '16 at 05:57

1 Answers1

11

Use Zip:

var result = lstId.Zip(lstName, (id, name) => new { id, name });
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263