Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "& _" mean in VB?

Tags:

vb.net

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:

*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.

like image 572
B. Clay Shannon-B. Crow Raven Avatar asked Oct 23 '13 17:10

B. Clay Shannon-B. Crow Raven


2 Answers

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

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

like image 147
Mansfield Avatar answered Oct 03 '22 08:10

Mansfield


_ means continue the statement on the following line.

so ... & _ means continue concatenating the string on the following line.

text = "One line string"
text = "Two line " & _
       "string"
like image 45
Daniel Imms Avatar answered Oct 03 '22 07:10

Daniel Imms