Line continuation in strings
Would be great to have the equivalent of @" some string " in c# in order to do line continuation in VB without the cumbersome " & _.
That would be particularly useful when writing SQL Statements.
SqlQry = @" SELECT
FROM TableName; "
Great suggestion! Internally we’re also clamoring for such a feature on the VB team for our own code. We’ve actually prototyped one potential implementation in the VB “Roslyn” and it’s definitely a feature we want to do.
It’s funny because we also phrase the question the same way ‘Need a VB equivalent to @"" strings’ but the funny thing is that VB already has an equivalent to @"" strings – regular "" strings. Normal C# strings allow escape sequences like “\n\r” and “\t” but VB has never supported such constructs (nor do we have any strong inclination to) – when you use a @"" string in C# you’re turning off the escape sequences and everything works like VB does normally – even escaping quotes with """" is the same. The only difference is that C# allows newlines inside of the string literal and VB doesn’t. Realizing this we said “Why don’t we just let people put newlines in normal strings” and there you have it In fact the entire prototype was just commenting out the line that said “When you hit a newline stop” :)
Your example would then look like this:
SqlQry = " SELECT
FROM TableName; "
We’d considered other designs, for example:
SqlQry = " Select
" FROM TableName; "
This had the advantage of letting you keep indentation intact but made it harder to just paste a block of text into the editor.
Regrettably this feature won’t be in the next release of Visual Studio but may appear sometime during or after the “Roslyn” time frame. Now, we have not announced a schedule for Roslyn but I hope this update provides you comfort in the meantime.
-Anthony D. Green, Program Manager, Visual Basic and C# Languages Team
Anthony D. Green commented
That's also the trick we're using. It leaves much to be desired, doesn't it?
Couldn't agree more. The trick I am currently using is to write my query within xml litteral, but that doesn't allow angle brackets, which is a problem for SQL queries:
Dim SqlQry = <Q>