Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Eric Lippert's challenge - cleanerererer2

By: a guest on Sep 10th, 2010  |  syntax: C#  |  size: 0.56 KB  |  hits: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. sealed class Dumper
  2. {
  3.     static public string Dump(Node root)
  4.     {
  5.         return Dump( root, "" );
  6.     }
  7.     static private string Dump(Node node, string indent)
  8.     {
  9.         return string.Format( "{0}\n{1}{2}", node.Text,
  10.             node.Children.Take(node.Children.Count - 1)
  11.                 .Aggregate("", (results, child) => string.Format( "{0}{1}├─{2}", results, indent, Dump(child, indent + "│ ") ) ),
  12.             node.Children.Count == 0 ? "" : string.Format( "{0}└─{1}", indent, Dump(node.Children.Last(), indent + "  " ) ) );
  13.     }
  14. }