Saturday, November 17, 2018

Multiline string literal in C#



Is there an easy way to create a multiline string literal in C#?



Here's what I have now:



string query = "SELECT foo, bar"
+ " FROM table"
+ " WHERE id = 42";



I know PHP has



<<
BLOCK;


Does C# have something similar?


Answer




You can use the @ 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.


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...