It is not possible to comment out a mid-line of a multiline statement?

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
the following code is broken.. can anyone tell me why?

VB.NET:
Dim s as String = _
  "hello" & _
  'myVariable & _
  "world"
 
The underscore simply tells the compiler that the current statement continues on the next line. When the compiler moves to the next line and runs into the apostrophe it closes the statement, leaving the last line out in the cold to generate the error. If you want to comment this line out temporarily rather than delete it, then move to the end of the statement block until you need to put it back in.
 
Just a tip...if you are compiling a string in sections use a stringbuilder.

Other than that you can use the following:
VB.NET:
[LEFT]Dim s as String
s &= "hello"
's &= myVariable
s &= "world"
[/LEFT]
 
Last edited by a moderator:
Another note - that's not using StringBuilder... that's simple concatenation... albiet as shorter one....
StringBuilder is an actual class in the .NET framework and is specialized in large sized strings.

-tg
 
second line starts "Other than that", I believe that means as an alternative to using a stringbuilder not as an example of using a stringbuilder.
 
*takes eyeballs out & cleans off the dust* Why so it does... hehe... my bad.

-tg
 
Back
Top