[Mono-dev] Action<T> used

Piotr Zurek p.zurek at gmail.com
Mon Jul 10 23:06:18 EDT 2006


Hi guys,

I have created a simple tree structure using List<T>.
Below is the metod that I use to count all the nodes in that structure.

        public void CountDescendants()
        {
            _totalcount = 0;
            Queue<Node> todo = new Queue<Node>();
            todo.Enqueue(this);
            while (todo.Count > 0)
            {
                Node node = todo.Dequeue();
                foreach (Node child in Node.Subnodes) todo.Enqueue(child);
                _totalcount++;
            }
        }

I have been podering on how to create a simple ForEach method for my
Node class that would allow me executing different commands on all
elements of the tree.
Probably the Action<T> delegate is the way to go here but I ain't got
a clue how to use it. Any ideas?

Cheers
Piotr



More information about the Mono-devel-list mailing list