B. Clay Shannon B. Clay Shannon - 3 months ago 7
Vb.net Question

What does "& _" mean in VB?

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.

Answer

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)