I have this class:
public class Node
{
public string Name {get; set;}
public Node Left {get; set;}
public Node Right{get; set;}
}
Now I have tree that each node has a left and right node, and each of them has left and right nodes and so on.
I want to get Name
s of all node in the tree, I couldn't do it with SelectMany.
I can do this in several ways like using a recursive function, but I'm really curious to know how is it done using Linq.
tree.SelectMany(x=> new List<Node> {x.Left, x.Right});
the above code just returns 2 Nodes (left and right nodes of the parent).