C# break string literal across multiple lines

I'd like to break a very long string literal across multiple lines in the source code.  In VB, this is done with the '_' (underscore) character dangling at the end.  How can I do this in C#?  I can't seem to find a line continuation character for C#.
rschaafAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WinterMuteUKCommented:
You could do it like this:

string str =
     "thi" +
     "s is a string";

admittedly it's not exactly the same.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomvergoteCommented:
the semicolon serves as a line ending, so you can just type breaks, they don't mean anything in c#, the command finishes with the ;
0
AvonWyssCommented:
C# sees line breaks as white space, that is, having the same meaning like a space or a tab. Therefore, everywhere where you can add spaces, you can also add line breaks without the need for a line contuinuation character.

Note that you can also span a string across multiple lines when using the literal string prefix:
string str=@"this is a string.
it contains two lines (not just in the source code)!";

Hope this helps.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

rschaafAuthor Commented:
The suggestion from AvonWyss helps, but it's still not the answer I'm lookng for.  In your example, "This is a string" and "it contains two lines" will be displayed on two lines when that string is displayed in a MessageBox, for example.  There is no real continuation happening.
0
AvonWyssCommented:
Well. If you write a literal string, it will also contain the line breaks. This is intentional, as you may have guessed by the contents of that two-line string. If you want to span it without line breaks, use the knowledge that "a"+"b" is the same as "ab" and that you may add any number and any type of whitespace between the string parts and operators (here the + operator):
string str="a"+
"b";
0
rschaafAuthor Commented:
Unless someone else chimes in, I'll assume that there is no line continuation character (analogous to the '_' char in VB).
0
WinterMuteUKCommented:
There isn't a line continuation character for the reason that tomvergote gave, and both my and AvonWyss' suggestions of the concatenation character '+' is the only way to do what you are looking for.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.