If I have these lists as inputs:
List<Record> A = new List<Record> { new Record { Value = 1 }, new Record { Value = 2 }, new Record { Value = 3 }, new Record { Value = 4 }, new Record { Value = 5 } };
List<Record> B = new List<Record> { new Record { Value = 1 }, new Record { Value = 2 }, new Record { Value = 5 }, new Record { Value = 7 } };
So from above, A has these elements:
Record{Value = 1}
Record{Value = 2}
Record{Value = 3}
Record{Value = 4}
Record{Value = 5}
And B has these elements:
Record{Value = 1}
Record{Value = 2}
Record{Value = 5}
Record{Value = 7}
I would like the following output. A List<Tuple<Record, Record>>
where, in our case, the list looks like:
Record{Value = 1} | Record{Value = 1}
Record{Value = 2} | Record{Value = 2}
Record{Value = 3} | null
Record{Value = 4} | null
Record{Value = 5} | Record{Value = 5}
null | Record{Value = 7}
The first column above, which represents the first element in our tuple, can only contain objects from A, or null. The second column above, which represents the second element in our tuple, can only contain objects from B, or null. Records have more than just a Value field, thus don't count them as value types otherwise I would have used integers in my question.
Basically, as you can see in the example, objects in A go into the first column, objects in B go into the second column of the output data type. If there are matches on the Value field, then they go side-by-side. If there are no matches on the value field between A and B, then null goes on the opposite side, wherever there is no match.
Is there any way to LINQ query data sets A and B to produce a resulting data type like this? I am not so strict on using a list of tuples. I would be okay with a dictionary, or some other type...