问题描述
为什么换行符(_)必须是该行的最后一个?这是否有技术原因,或者这是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"?
在其他基本方言中,您可以在其后添加注释,但不能在VB.net中添加注释.因此,我很好奇Microsoft为何决定不允许在这些行中添加注释.
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.
推荐答案
由于反汇编的代码看起来没有什么不同,因此必须将其烘焙到编译器中.看一下下面的代码:
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看起来像这样:
MSIL looks at it like this:
IL_0000:nop
IL_0001:ldstr"John"
IL_0006:stloc.1
IL_0007:ldstr你好"
IL_000c:ldloc.1
IL_000d:ldstr.您好吗??"
IL_0012:调用字符串[mscorlib] System.String :: Concat(string,
字符串,
字符串)
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相同:
IL_0000:nop
IL_0001:ldstr"John"
IL_0006:stloc.1
IL_0007:ldstr你好"
IL_000c:ldloc.1
IL_000d:ldstr.您好吗??"
IL_0012:调用字符串[mscorlib] System.String :: Concat(string,
字符串,
字符串)
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)
因此,这是编译器的功能".为什么要这样呢?在解释有关VB.NET的任何内容时,您需要回顾经典的Visual Basic.许多原理和过程只是为了使用户感到舒适和吸引VB6及更早的程序员而刚开始使用VB.NET.因此,为什么在VB.NET(2008及更早版本)中采用这种方式,可能是因为在VB6及更早版本中采用了这种方式.而且我敢冒险猜测,由于在编译代码之前受IDE的限制,所以它是在VB6中完成的,但是我们永远无法知道,除非最初的VB6微软团队的人在其背后添加了更多的理由.
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.
希望这会有所帮助!
这篇关于为什么VB.Net行继续符必须是行中的最后一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!