Multiline string literal in C#

后端 未结 13 1797
梦谈多话
梦谈多话 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:27

    Add multiple lines : use @

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

    Add String Values to the middle : use $

    string text ="beer";
    string query = $"SELECT foo {text} bar ";
    

    Multiple line string Add Values to the middle: use $@

    string text ="Customer";
    string query = $@"SELECT foo, bar
    FROM {text}Table
    WHERE id = 42";
    

提交回复
热议问题