Counting descendants in a tree
<p>I have the following class which recurs on itself to form a tree-like data structure:        </p>

<pre><code>public class chartObject
{
    public string name { get; set; }
    public int descendants { get; set; }
    public List&lt;chartObject&gt; children { get; set; }
}
</code></pre>

<p>For each object in the tree I would like to populate the descendant property with the amount objects that exist underneath it.</p>

<p>Example structure:</p>

<pre><code>chartObject1 (descendants: 4)
└-chartObject2 (descendants: 0)
└-chartObject3 (descendants: 2)
└--chartObject4 (descendants: 1)
└---chartObject5 (descendants: 0)
</code></pre>

<p>What would be the most efficient way of doing this?</p>
