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#?
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 .
Use the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With