patterncsharpCritical
Multiline string literal in C#
Viewed 0 times
stringmultilineliteral
Problem
Is there an easy way to create a multiline string literal in C#?
Here's what I have now:
I know PHP has
Does C# have something similar?
Here's what I have now:
string query = "SELECT foo, bar"
+ " FROM table"
+ " WHERE id = 42";I know PHP has
<<<BLOCK
BLOCK;Does C# have something similar?
Solution
You can use the
You also do not have to escape special characters when you use this method, except for double quotes as shown in Jon Skeet's answer.
@ symbol in front of a string to form a verbatim string literal:string query = @"SELECT foo, bar
FROM table
WHERE id = 42";You also do not have to escape special characters when you use this method, except for double quotes as shown in Jon Skeet's answer.
Code Snippets
string query = @"SELECT foo, bar
FROM table
WHERE id = 42";Context
Stack Overflow Q#1100260, score: 2167
Revisions (0)
No revisions yet.