【发布时间】:2017-04-27 10:46:55
【问题描述】:
在For Each 循环中,如果我们在Next 语句之后添加有问题的元素,会有区别吗?
也就是说,下面这两种有效方式有什么区别?
For Each Element in MyCollection
'...code
Next
For Each Element in MyCollection
'...code
Next Element
【问题讨论】:
-
据我所知,这纯粹是为了更容易阅读和跟踪您的嵌套。上面没有太大区别,但在有很多嵌套循环的代码中它确实有帮助。 (和缩进一样)
-
一个快速的谷歌会显示这个答案。 msdn.microsoft.com/en-us/library/5ebk1751.aspx。
You can optionally specify element in the Next statement. This improves the readability of your program, especially if you have nested For Each loops. You must specify the same variable as the one that appears in the corresponding For Each statement. -
好的,谢谢你的信息!