Creating multi-line string literals in C#
Multiline string literals allow you to define strings across multiple lines. In C#, there are two ways to create multiline string literals.
1. Verbatim string literal:
You can create a verbatim string literal by adding the "@" symbol before the string literal. This allows you to include newlines, special characters, and spaces as-is.
string query = @"SELECT foo, bar FROM table WHERE id = 42";
2. String interpolation:
Alternatively, you can use string interpolation to create multiline strings. This method requires C# 6.0 or higher.
string query = $"SELECT foo, bar FROM table WHERE id = 42";
In both cases you can avoid escaping special characters except double quotes in the string.
The above is the detailed content of How Can I Create Multiline String Literals in C#?. For more information, please follow other related articles on the PHP Chinese website!