Using LINQ to find a common prefix?
- by Roger Lipscombe
I've got two sequences:
IEnumerable<string> x = new[] { "a", "b", "c" };
IEnumerable<string> y = new[] { "a", "b", "d", "e" };
I'd like to find the common prefix of these two sequences (i.e. "a", "b"). Is there a succinct way to do this in LINQ?
Bear in mind that these aren't really IEnumerable<string>; they're IEnumerable<PathComponent>, where I have an implementation of IEqualityComparer<PathComponent>.