vb.net “& _”在VB中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19548848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:15:20  来源:igfitidea点击:

What does "& _" mean in VB?

vb.net

提问by B. Clay Shannon

I'm copying some query statements from a legacy VB app to a C# app. I am not familiar with VB, although looking at it makes me want a VB (Victoria Bitter). I have come across queries constructed like this:

我正在将一些查询语句从旧版 VB 应用程序复制到 C# 应用程序。我不熟悉 VB,虽然看着它让我想要一个 VB(Victoria Bitter)。我遇到过这样构造的查询:

*SELECT dp_duckbill_accounts.platypus_no AS duckbill, t_accounts.name AS Name " & _ 
"FROM t_accounts INNER JOIN dp_duckbill_accounts ON  t_accounts.account_no = dp_duckbill_accounts.account_no " & _
"ORDER BY dp_duckbill_accounts.platypus_no*

The "& _" give me pause. If it was just "&" I would think it corresponds to "+" in C# to concatenate strings. But what in the world is the point of the underscore? Note the ampersand and the underscore are separated by a space.

“& _”让我停下来。如果它只是“&”,我会认为它对应于 C# 中的“+”来连接字符串。但是下划线的重点是什么?请注意,与号和下划线之间用空格分隔。

回答by Mansfield

The underscore is the line continuation character. It allows the concatenation to include a different line. Like so:

下划线是换行符。它允许连接包含不同的行。像这样:

x = "Hello " & "World"

x = "Hello " & _
    "World"

'this won't compile (pre vb.net 2010, anyway)
    x = "Hello " & 
    "World"

Line Continuation on MSDN

MSDN 上的续行

How to: Break and Combine Statements in Code (Visual Basic)

如何:在代码中拆分和组合语句 (Visual Basic)

回答by Daniel Imms

_means continue the statement on the following line.

_表示继续下一行的语句。

so ... & _means continue concatenating the string on the following line.

so... & _意味着继续连接下一行的字符串。

text = "One line string"
text = "Two line " & _
       "string"

回答by Justin E

That is just a line continuation character that lets you continue to the next line.

这只是一个行继续符,可让您继续到下一行。

回答by Chandralal

& - is used for string concatenation in same line. example - sConcatenatedString = "First" & "Second"

& - 用于同一行中的字符串连接。 示例 - sConcatenatedString = "First" & "Second"

& _ - is used For string concatenation in different lines. example - sConcatenatedString = "First" &_ "Second"

& _ - 用于不同行中的字符串连接。 示例 - sConcatenatedString = "First" &_ "Second"