【在树形结构C#中查找T类型的所有对象】教程文章相关的互联网学习教程文章

在树形结构C#中查找T类型的所有对象【代码】

我需要编写一个树搜索方法,它接受一个类型参数T并返回树中存在的所有T类型的项.有没有办法做到这一点?在这一点上,我宁愿优雅而不是效率……解决方法:像这样的东西:internal static IEnumerable<T> AllDescendantNodes<T>( this TreeNode input ) where T class; {T current = null;foreach ( TreeNode node in input.Nodes )if( (current = node as T) != null ){yield return current;foreach ( var subnode in node.AllDescend...