VB.NET 换行更改

发布于 2024-12-22 20:07:37 字数 81 浏览 1 评论 0原文

有谁知道我是否可以找到不再需要换行符 (_) 的列表。到目前为止,我注意到参数列表和属性现在可以在没有换行符的情况下工作。

Does anyone know if I can find a list of where the line break (_) is no longer required. So far I notice parameter lists and attributes now work without the line break char.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

战皆罪 2024-12-29 20:07:37

从技术上讲,它称为行继续字符

这不是 .NET Framework 版本的功能,而是编译器的功能。第一个支持它的版本是 VB.NET 10,它包含在 Visual Studio 2010 中。

新功能已记录在 此处,包括一个很好的表格,列出了隐式延续的情况。

Visual Basic 是一种面向行的语言,它使用清晰的、类似英语的语法来增强可读性。但这通常会导致代码超出每行 80 个字符的限制,迫使开发人员大量滚动。您可以使用下划线字符告诉编译器它应该继续将下一行作为当前行的一部分进行处理(即将多个物理行视为单个逻辑行)。但必须重复输入下划线一直很烦人,事实上,多年来,第一大功能请求一直是编译器“弄清楚它”。

嗯,在 Visual Basic 2010 中,编译器可以。现在,它知道哪些标记(例如逗号、括号和运算符)往往出现在续行符之前,并且它会插入该字符,以便开发人员不再需要这样做。例如,以逗号结束 Visual Basic 语句是不合法的;编译器知道这一点,因此当它看到类似于 {comma, Enter} 的标记流时,它会推断出行继续符的存在

[ 。 。 。 ]

如您所见,该语言有 60 多个地方不需要下划线。 (事实上​​,本文中的代码示例都不需要行继续字符。)当然,您仍然可以使用下划线,因此 Visual Basic 早期版本的代码仍将按预期进行编译。

Technically speaking, it's called a line continuation character.

This is not a feature of the .NET Framework version, it's a feature of the compiler. The first version to support it is VB.NET 10, the one included with Visual Studio 2010.

The new feature is documented here, including a nice table listing where continuation is implicit.

Visual Basic is a line-oriented language that uses clear, English-like syntax to enhance readability. But that often results in code that runs up against the 80-character-per-line limit, forcing developers to scroll a lot. You can use the underscore character to tell the compiler that it should keep processing the next line as part of the current one (that is, treat multiple physical lines as a single, logical line). But having to type underscores repeatedly has always been annoying, and in fact, for years the No. 1 feature request has been for the compiler to “just figure it out.”

Well, in Visual Basic 2010, the compiler can. It now knows which tokens (such as commas, parentheses and operators) tend to occur right before the line-continuation character, and it inserts the character so developers no longer need to. For example, ending a Visual Basic statement with a comma is never legal; the compiler knows this, so when it sees a token stream that looks like {comma, enter}, it infers the presence of the line continuation character

[ . . . ]

As you can see, there are more than 60 places where the language doesn’t require underscores. (In fact, none of the code samples in this article required the line-continuation character.) Of course, you can still use the underscore, so code from previous versions of Visual Basic will still compile as expected.

以可爱出名 2024-12-29 20:07:37

可以换行的位置的规则没有改变。对于更高版本的编译器,您根本不再需要 _ 。

The rules for where you can break a line haven't changed. You just no longer need the _ at all with the later compilers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文