有没有一种体面的方法可以在 C# 中声明一个长的单行字符串,以便在编辑器中声明和/或查看字符串不是不可能的?
我知道的选项是:
1:让它运行。这很糟糕,因为您的字符串拖到屏幕右侧,使阅读消息的开发人员不得不烦人的滚动和阅读。
string s = "this is my really long string. this is my really long string. this is my really long string. this is my really long string. this is my really long string. this is my really long string. this is my really long string. this is my really long string. ";
2:@+换行符。这在代码中看起来不错,但在字符串中引入了换行符。此外,如果您希望它在代码中看起来不错,您不仅会得到换行符,而且还会在字符串的每一行的开头出现尴尬的空格。
string s = @"this is my really long string. this is my long string.
this line will be indented way too much in the UI.
This line looks silly in code. All of them suffer from newlines in the UI.";
3:"" + ...
这很好用,但打字非常令人沮丧。如果我需要在某处添加半行的文本,我必须更新各种 + 并移动文本。
string s = "this is my really long string. this is my long string. " +
"this will actually show up properly in the UI and looks " +
"pretty good in the editor, but is just a pain to type out " +
"and maintain";
4 string.format or string.concat
:。与上面基本相同,但没有加号。具有相同的优点和缺点。
真的没有办法做好这件事吗?