Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line continue character in C#

Tags:

c#

We have a unit test with variable that contains a very long string.

Question is how to write this in code, without having problems with line breaks or that the code is difficult to read.

In VB there is a line continue character, is there an equivilant in C#?

like image 835
Shiraz Bhaiji Avatar asked Nov 03 '10 10:11

Shiraz Bhaiji


People also ask

Can you break lines in C?

There is a character for that. It's called "newline". You can't put it directly in the string because that would create a new line in the source code, but inside quotes in C you can produce it with \n .

How do you continue line of code?

Use the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break.

What is the line continuation character and what does it do?

The line continuation character in IPL and JavaScript is the backslash (\). You use this character to indicate that the code on a subsequent line is a continuation of the current statement. The line continuation character helps you format your policies so that they are easier to read and maintain.

How do you span a line of code in C++?

As far as I am aware, you can just press enter and continue on the next line as normal. C++ ignores whitespace so the line will go on until you terminate it with a semicolon.


1 Answers

C# will allow you to have a string split over multiple lines, the term is called verbatim literal:

string myString = @"this is a                     test                    to see how long my string                    can be                        and it can be quite long"; 

If you are looking for the alternative to & _ from VB, use the + to join your lines.

like image 197
Neil Knight Avatar answered Oct 06 '22 00:10

Neil Knight