Skip to content

Instantly share code, notes, and snippets.

@amantix
Created March 27, 2018 17:58
Show Gist options
  • Save amantix/ce231ce0d18e4875d1b4aa1d5ac011e7 to your computer and use it in GitHub Desktop.
Save amantix/ce231ce0d18e4875d1b4aa1d5ac011e7 to your computer and use it in GitHub Desktop.
Left outer join
public static void LinqBegin54()
{
IEnumerable<string> a
= new[] {"AA", "B21", "A32", "VS", "S", "AAA"};
IEnumerable<string> b
= new[] {"B2", "BSS3", "AD6", "SSS"};
/*
var result =
a.GroupJoin(b, x => x[0], x => x[0],
(x, y) => y.DefaultIfEmpty("")
.Select(z => x + "." + z))
.SelectMany(x => x)
.OrderBy(x => x);
*/
var result =
from x in a
join y in b
on x[0] equals y[0]
into yy
from z in yy.DefaultIfEmpty("")
orderby x, z
select x + "." + z;
Console.WriteLine(string.Join(" ", result));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment