Best way to break long strings in C# source code

后端 未结 10 1472
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 18:47

I am wondering what is the \"best practice\" to break long strings in C# source code. Is this string

\"string1\"+
\"string2\"+
\"string3\"

con

10条回答
  •  不思量自难忘°
    2021-02-03 19:41

    If the whitespace isn't important then you can use the @ escape character to write multi-line strings in your code. This is useful if you have a query in your code for example:

    string query = @"SELECT whatever
    FROM tableName
    WHERE column = 1";
    

    This will give you a string with line breaks and tabs, but for a query that doesn't matter.

提交回复
热议问题