vb.net - 对于每个 x ... 下一个与。对于每个 x ...下一个 x

标签 vb.net syntax

通常,我使用 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.

原文可在此处找到 - 备注部分下的第五段:

http://msdn.microsoft.com/en-us/library/5ebk1751.aspx

关于vb.net - 对于每个 x ... 下一个与。对于每个 x ...下一个 x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11830247/

相关文章:

mysql - SQL 查询和线程

c# - VB.NET 相当于 C# var 关键字

asp.net - 本地化:如果在切换文化时 URL 没有改变,SE 是否认为它是重复内容?

javascript - 使用提示框中的输入并将其保存到数据库

c++ - 在 C++ 中通过引用返回

asp.net - <#=#>是什么意思

mysql - 将数据 GridView 行添加到 vb.net 中的 sql 表

c++ - C/C++ : Perimeter and area of rects. 长方体的体积

Haskell: 'do' 构造中的最后一个语句必须是表达式

R t.test() 以 data.frames 作为参数