Multiline string literals in C#: how to write long text without escaping?
Hello colleagues! I'm new to C# and ran into a problem. I need to store a long text in a variable, for example, an SQL query, JSON, or just a multiline message. In other languages (Python, JavaScript) I can use triple quotes or template strings, and it works nicely there. But in C# I can't find a convenient way.
Here's an example of what I'm trying to do:
```csharp
string query = "SELECT * FROM Users
WHERE Age > 18
ORDER BY Name;";
```
The compiler gives an error because you can't have a line break inside double quotes. I tried using the `\n` character:
```csharp
string query = "SELECT * FROM Users\nWHERE Age > 18\nORDER BY Name;";
```
But this only works if I want a single string with line breaks, not readable multiline code. In a real project
No answers yet.
Log in to leave an answer