Example: Get all node of the TreeView, save to List<treenode>, and encapsulate to the generic tool class:
Method One: Empty the static type list before using the static method, property---Call
1 Public StaticList<treenode> allnodes =NULL;2 Public Static voidgettreeviewallnodes (treenodecollection Nodes)3 {4 foreach(TreeNode nodeinchNodes)5 {6 allnodes.add (node);7 if(node. Childnodes.count >0)8 {9 gettreeviewallnodes (node. ChildNodes);Ten } One } A } - Public StaticList<treenode>getnodes (TreeView TV) - { the gettreeviewallnodes (TV. Nodes); - returnAllnodes; -}
Note: If you use a static type list, you need to empty the list<treenode> before calling the generic tool class, otherwise the overlay will appear. In the constructor, empty:
Public Tools () { allnodes.clear (); }
Method Two, use the internal method, the property---call directly
1 PublicList<treenode> allnodes =NewList<treenode>();2 Public voidgettreeviewallnodes (treenodecollection Nodes)3 {4 foreach(TreeNode nodeinchNodes)5 {6 allnodes.add (node);7 if(node. Childnodes.count >0)8 {9 gettreeviewallnodes (node. ChildNodes);Ten } One } A } - PublicList<treenode>getnodes (TreeView TV) - { the gettreeviewallnodes (TV. Nodes); - returnAllnodes; -}
Question: Can you use a method to both iterate and get the return value???
Loop recursion + return value (treeview example)