In C#, what's the best way to spread a single-line string literal across multiple source lines?

前端 未结 7 1537
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 18:19

Suppose that you have a lengthy string (> 80 characters) that you want to spread across multiple source lines, but don\'t want to include any newline characters.

One

7条回答
  •  时光说笑
    2020-12-30 19:04

    For SQL queries or other long strings that have their own syntax, I'll sometimes do something like this:

            private const string QUERY = @"
    SELECT *
    FROM Table1 AS T1
    INNER JOIN Table2 AS T2 ON T1.ID = T2.T1ID
    WHERE T1.VALUE = @P1
    GROUP BY T2.OTHERVALUE
    ";
    

    This leaves the formatting of the string intact.

提交回复
热议问题