2021年4月24日星期六

Linq pairing two Lists of different classes with join

I have the code below

var allA = // holds a List<classA>  var allB = //holds a List<ClassB>  var res = from A in allA          join B in allB on A.Id equals B.Id           select new Tuple<string,string,string,string,string>                      (B.val1,B.val2,A.val1,A.val2,A.val3);    var resList = res as List<Tuple<string, string, string, string, string>>;  

Now the issue is, with the way im doing it I'd have to remember which item in my tuples hold what value. I don't why resList = res as a List<Tuple<...>> doesn't work either, it doesn't hold any values.

How can I structure this where I have a List<Tuple<ClassA,ClassB>> and in each tuple, ClassA and ClassB are the joined pair in Linq select statement?

https://stackoverflow.com/questions/67248410/linq-pairing-two-lists-of-different-classes-with-join April 25, 2021 at 07:36AM

没有评论:

发表评论