fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var oldList = new List<int?> { 2, 3, 4, 5 };
  10. var newList = new List<int?> { 1, 2 };
  11. var result = from all in oldList.Union(newList).OrderBy(num => num)
  12. join o in oldList on all equals o into gjOld
  13. from oldOuter in gjOld.DefaultIfEmpty((int?)null)
  14. join n in newList on all equals n into gjNew
  15. from newOuter in gjNew.DefaultIfEmpty((int?)null)
  16. select new { newVal = newOuter, oldVal = oldOuter };
  17. foreach(var x in result)
  18. Console.WriteLine("newVal: {0} oldVal: {1}", x.newVal, x.oldVal);
  19. }
  20. }
Success #stdin #stdout 0.06s 34240KB
stdin
Standard input is empty
stdout
newVal: 1 oldVal: 
newVal: 2 oldVal: 2
newVal:  oldVal: 3
newVal:  oldVal: 4
newVal:  oldVal: 5