在 VB.NET 中使用 Yield 时出错 - 方法参数必须括在括号中
Error using Yield in VB.NET - Method arguments must be enclosed in parentheses
我正在尝试为 return IEnmerable(Of Control)
中某个控件的所有后代创建一个递归函数。我创建了一个函数 returning IEnumerable(Of Control)
并使用了 Yield
:
Public Function GetControls(C As Control) As IEnumerable(Of Control)
For Each Child As Control In C.Controls
Yield Child
For Each GrandChild In GetControls(Child)
Yield GrandChild
Next
Next
End Function
但是我有一个编译时错误:
Error BC30800, Method arguments must be enclosed in parentheses.
我尝试像函数 Yield(Child)
或 Yield Return Child
或 Return Yield Child
一样使用它,但仍然有错误。
通过在 google 或 bing 中搜索错误消息,我找不到任何与问题相关的内容。我该如何解决这个问题?
在VB.NET中使用Yield
语句时,函数应定义为Iterator
:
Public Iterator Function GetControls(C As Control) As IEnumerable(Of Control)
For Each Child As Control In C.Controls
Yield Child
For Each GrandChild In GetControls(Child)
Yield GrandChild
Next
Next
End Function
我正在尝试为 return IEnmerable(Of Control)
中某个控件的所有后代创建一个递归函数。我创建了一个函数 returning IEnumerable(Of Control)
并使用了 Yield
:
Public Function GetControls(C As Control) As IEnumerable(Of Control)
For Each Child As Control In C.Controls
Yield Child
For Each GrandChild In GetControls(Child)
Yield GrandChild
Next
Next
End Function
但是我有一个编译时错误:
Error BC30800, Method arguments must be enclosed in parentheses.
我尝试像函数 Yield(Child)
或 Yield Return Child
或 Return Yield Child
一样使用它,但仍然有错误。
通过在 google 或 bing 中搜索错误消息,我找不到任何与问题相关的内容。我该如何解决这个问题?
在VB.NET中使用Yield
语句时,函数应定义为Iterator
:
Public Iterator Function GetControls(C As Control) As IEnumerable(Of Control)
For Each Child As Control In C.Controls
Yield Child
For Each GrandChild In GetControls(Child)
Yield GrandChild
Next
Next
End Function