通常,我使用 C# 编写 .NET 程序,但目前我正在更新一个用 VB.NET 编写的项目,并注意到 For Each
循环中使用了一种奇怪的语法。
有什么区别吗
For Each x in collection.Items
...
Next
和
For Each x in collection.Items
...
Next x
?
我在这里的代码中看到了这两种情况,并且很好奇为什么有人会使用第二种变体。
最佳答案
这在 MSDN 引用中是这样指定的:
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.
原文可在此处找到 - 备注部分下的第五段:
关于vb.net - 对于每个 x ... 下一个与。对于每个 x ...下一个 x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11830247/