using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { static class Class1 { private static IEnumerable GetChildren( TNode node, Func> GetNodes) { var nodes = GetNodes(node); return nodes.Concat(nodes.SelectMany(x => GetChildren(x, GetNodes))); } public static IEnumerable GetChildrenRecursively( this TRoot obj, Func> EnumRoot, Func> GetNodes) { var nodes = EnumRoot(obj); return nodes.Concat(nodes.SelectMany(x => GetChildren(x, GetNodes))); } } class Program { static void Main(string[] args) { int[] arr = { 1, 2, 3, 4 }; var query = arr.GetChildrenRecursively, IEnumerable>(x => arr.Select(y => new int[] { y }), x => arr.Except(x).Select(y => x.Concat(new int[] { y }.ToArray()))); foreach (var item in query) { foreach (var i in item) Console.Write(i + " "); Console.WriteLine(); } } } }