Multiline string literal in C#

后端 未结 13 1465
梦谈多话
梦谈多话 2020-11-22 11:15

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\"
+ \" W         


        
13条回答
  •  名媛妹妹
    2020-11-22 11:30

    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.

提交回复
热议问题