Foreach 无法对方法组进行操作
private void PrintRecursive(TreeNode treeNode)
{
foreach (TreeNode tn in treeNode.Nodes)
{
PrintRecursive(tn);
}
}
我收到错误:Foreach 无法对方法组进行操作。您打算调用“方法组”吗?
private void PrintRecursive(TreeNode treeNode)
{
foreach (TreeNode tn in treeNode.Nodes)
{
PrintRecursive(tn);
}
}
I get the error: Foreach cannot operate on a method group. Did you intend to invoke the 'method group'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里的问题是
Nodes
是一个方法,但您用作属性:)所以这行代码
应该是
The problem here is that
Nodes
is a method but you use as property :)So this line of code
should be
假设您使用的是打包的 TreeView 控件,它不应该是
ChildNodes
吗?:Assuming you're using the packaged TreeView control, shouldn't it be
ChildNodes
?:TreeView.Nodes 给出TreeNode 对象的集合,表示 TreeView 控件中的根节点。
要访问根节点的子节点,请使用 ChildNodes 节点的属性。
例如使用 for 循环
或使用 foreach
TreeView.Nodes gives a collection of TreeNode objects that represents the root nodes in the TreeView control.
To access the child nodes of a root node, use the ChildNodes property of the node.
e.g. using for loop
or using foreach