Klasse für eine dynamische Baumstruktur

class CTreeNode
{
    private uint _uiID = 0;
    private string _sName = string.Empty;
    private double _dValue = 0.0;
    private List<CTreeNode> _Childs = null;

    public uint ID
    {
        get
        {
            return _uiID;
        }
    }

    public string Name
    {
        get
        {
            return _sName;
        }
    }

    public double Value
    {
        get
        {
            return _dValue;
        }
        set
        {
            _dValue = value;
        }
    }

    // Addiert eigenen Wert zu allen Kind-Werten
    public double Sum
    {
        get
        {
            double dSum = _dValue;

            foreach (CTreeNode c in _Childs)
            {
                dSum += c.Sum;
            }

            return dSum;
        }
    }

    // Liste der Kind-Knoten
    public List<CTreeNode> Childs
    {
        get
        {
            return _Childs;
        }
    }

    public CTreeNode(uint uiID, string sName, double dValue)
    {
        _uiID = uiID;
        _sName = sName;
        _dValue = dValue;
        _Childs = new List<CTreeNode>();
    }
}

// Anwendung
CTreeNode r = new CTreeNode(0, "Wurzel", 1.0);

CTreeNode k1 = new CTreeNode(1, "Kind 1_1", 1.0);
CTreeNode k2 = new CTreeNode(2, "Kind 1_2", 2.0);
r.Childs.Add(k1);
r.Childs.Add(k2);

CTreeNode k3 = new CTreeNode(3, "Kind 2_1_1", 3.0);
CTreeNode k4 = new CTreeNode(4, "Kind 2_1_2", 4.0);
k1.Childs.Add(k3);
k1.Childs.Add(k4);

CTreeNode k5 = new CTreeNode(5, "Kind 2_2_1", 5.0);
CTreeNode k6 = new CTreeNode(6, "Kind 2_2_2", 6.0);
k2.Childs.Add(k5);
k2.Childs.Add(k6);

// dSum == 22.0
double dSum = r.Sum;