为什么VB.Net行继续符必须是行的最后一个

发布于 2024-09-20 00:20:15 字数 141 浏览 3 评论 0原文

为什么行继续符 (_) 必须是该行的最后一个?这是否有技术原因,或者这是 Microsoft 的常见“功能”?

在其他基本方言中,您可以在其后添加注释,但在 VB.net 中则不行,所以我很好奇为什么 Microsoft 决定不允许在这些行上添加注释。

Why must the line continuation character (_) be the last one on the line? Is there a technical reason for this or is this a usual Microsoft "feature"?

In other basic dialects you can add a comment after it, but not in VB.net, so I'm curious as to why Microsoft decided to not allow comments on these lines.

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

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

发布评论

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

评论(2

旧城空念 2024-09-27 00:20:15

它必须被烘焙到编译器中,因为反汇编的代码看起来没有什么不同。看一下下面的代码:

    Dim nameVar As String = "John"
       MsgBox("Hello " & nameVar & _
              ". How are you?")

MSIL 看起来像这样:

IL_0000: nop
IL_0001:ldstr“约翰”
IL_0006:stloc.1
IL_0007:ldstr“你好”
IL_000c:ldloc.1
IL_000d:ldstr“。你好吗?”
IL_0012:调用字符串 [mscorlib]System.String::Concat(string,
字符串,
字符串)

现在没有续行的相同代码:

        Dim nameVar As String = "John"
        MsgBox("Hello " & nameVar & ". How are you?")

MSIL 相同:

IL_0000: nop
IL_0001:ldstr“约翰”
IL_0006:stloc.1
IL_0007:ldstr“你好”
IL_000c:ldloc.1
IL_000d:ldstr“。你好吗?”
IL_0012:调用字符串 [mscorlib]System.String::Concat(string,
字符串,
字符串)

所以这是编译器的“功能”。为什么要这样做呢?在解释有关 VB.NET 的任何内容时,您需要回顾经典的 Visual Basic。许多原理和过程只是为了舒适度并吸引 VB6 和早期程序员而被继承到 VB.NET。那么为什么 VB.NET(2008 年及之前)是这样的,可能是因为 VB6 及更早版本也是这样。我大胆猜测,由于编译代码之前 IDE 的限制,VB6 中是这样做的,但我们永远无法知道这一点,除非来自原始 VB6 Microsoft 团队的某人在其背后添加了他们的推理。

希望这有帮助!

It has to be baked into the compiler, because the disassembled code looks no different. Take a look at the following code:

    Dim nameVar As String = "John"
       MsgBox("Hello " & nameVar & _
              ". How are you?")

MSIL looks at it like this:

IL_0000: nop
IL_0001: ldstr "John"
IL_0006: stloc.1
IL_0007: ldstr "Hello "
IL_000c: ldloc.1
IL_000d: ldstr ". How are you\?"
IL_0012: call string [mscorlib]System.String::Concat(string,
string,
string)

Now the same code without line continuation:

        Dim nameVar As String = "John"
        MsgBox("Hello " & nameVar & ". How are you?")

MSIL is identical:

IL_0000: nop
IL_0001: ldstr "John"
IL_0006: stloc.1
IL_0007: ldstr "Hello "
IL_000c: ldloc.1
IL_000d: ldstr ". How are you\?"
IL_0012: call string [mscorlib]System.String::Concat(string,
string,
string)

So this is a "feature" of the compiler. Why do it this way? When explaining anything about VB.NET, you need to look back to classic Visual Basic. Many of the principals and procedures were simply just Grandfathered to VB.NET for a comfort level and to attract VB6 and earlier programmers. So why it is the way in VB.NET (2008 and before) is probably because it was that way in VB6 and earlier. And I would venture to guess it was done that way in VB6 because of IDE limitations prior to compiling the code, but we can never know that unless somebody from the original VB6 Microsoft team added thier reasoning behind it.

Hope this helps!

錯遇了你 2024-09-27 00:20:15

一位从事 Microsoft VB.Net 工作的开发人员有一个 关于这个想法的博客文章。他说这是一个好主意,但需要一些编译器重构。

如果您认为应该优先考虑,可以在博客上发表评论。或者在 Microsoft Connect 上提出建议。

One of the developers who works on Microsoft VB.Net has a blog post about this idea. He says it's a nice idea but requires some compiler refactoring.

If you think it should be prioritised, you could leave a comment on the blog. Or suggest something at Microsoft Connect.

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