Is there a way in C# sytax for defining a new line? (Like in VB _ )
Example:
Instead of:
string myStr = "very long string" +
"another long string";
This:
string myStr = "very long string \something
another long string"
Or; does compiler handles this and does something like; "string" + "string" -> "stringstring" in this example?
Different cases are welcome like when these strings are constants, etc.
In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
The newline character ( \n ) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
Line breaks differ between platforms in strings, although the most frequent ones are: Windows: Carry return \r\n followed by a character on the newline. Linux: \n a character on a newline. Older Macs: a character returned by a carriage.
In programming languages, such as C, Java, and Perl, the newline character is represented as a '\n' which is an escape sequence.
Compiler turns "ABC" + "DEF" into "ABCDEF" so there's no cost in using +
You can use
string myStr = @"very long string
another long string";
@" is the beginning of a string literal and this kind of string does not end until the next " character is found.
There is not an exact syntax for c# which does the same thing as _ character in vb. So if you want to avoid including a new line, you must manually connect your strings on different 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