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

前端 未结 7 1541
没有蜡笔的小新
没有蜡笔的小新 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:01

    If you want to keep the code as minimal as you can and be able to read it easily I would still go with a @ literal string. Plus its faster if you source is long and..

    string verbatimLit = @" 
       __   __  
      /  `-'  \ 
     /_| N   |_\  Sometimes
       |  I  |    format in code
       |   N |    matters
       |_____|  
    ";
    

    Then remove the newlines from the string in 1 line,

    verbatimLit.Replace(Environment.NewLine, " ");
    

提交回复
热议问题