Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* LINQ Puzzle #10 *******************************************************
- Summary: Assume we have a generic class that forms a tree like the Node class below.
- Given an IEnumerable of Nodes, write an extension method that flattens all the nodes
- of the tree(s) into a single list of nodes. The method MUST capable of accepting a
- generic class. The only assumption you can make is that it has some property that
- contains an IEnumerable of children of the same type.
- ************************************************************************/
- void Main()
- {
- var nodes = Enumerable.Range(0, 3).Select(x => new Node() {
- Children = Enumerable.Range(0, 3).Select(y => new Node() {
- Children = Enumerable.Range(0, 1).Select(z => new Node()).ToList()
- }).ToList()
- }).ToList();
- // call your extension method here
- }
- public class Node {
- public Node()
- {
- Guid = Guid.NewGuid();
- }
- public Guid Guid { get; set; }
- public IEnumerable<Node> Children { get; set; }
- }
- // write your extension method here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement