Skip to content

Instantly share code, notes, and snippets.

@icedog48
Created March 18, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save icedog48/71cf83cd95bcfb6810451c14cd62fe20 to your computer and use it in GitHub Desktop.
Save icedog48/71cf83cd95bcfb6810451c14cd62fe20 to your computer and use it in GitHub Desktop.
C# - How to flatten tree via LINQ ?
///http://stackoverflow.com/questions/11830174/how-to-flatten-tree-via-linq
public static IEnumerable<T> Flatten<T>(
this IEnumerable<T> e,
Func<T,IEnumerable<T>> f)
{
return e.SelectMany(c => f(c).Flatten(f)).Concat(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment