[Mono-dev] Action<T> used
latency at gmx.de
Tue Jul 11 03:27:39 EDT 2006
if I'm not mistaken you want to enumerate through all the elements in your
tree by simple using foreach, but you cant.
In that case you may take a closer look at the IEnumerable and IEnumerator
If an class is marked as IEnumerable it can be used in a foreach statement.
Because in the statement the compiler accesses the IEnumerator for that
object. The IEnumerator provides methods to access each and every element in
your collection. The actual implementation of the IEnumerator depends on how
your list stores its elements and how you may access them.
Hope I could be of any help.
On Tuesday 11 July 2006 05:06, Piotr Zurek wrote:
> 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>();
> while (todo.Count > 0)
> Node node = todo.Dequeue();
> foreach (Node child in Node.Subnodes) todo.Enqueue(child);
> 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?
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
More information about the Mono-devel-list