日期:2014-05-20  浏览次数:21883 次

在C#中如何定义长字符串?
有一个字符串较长比如
"abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmn ",不想再一行里面定义比如:
string   s   = "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmn "
希望分行,显得code整洁。应该如何定义?

------解决方案--------------------
StringBuilder myBuilder = new StringBuilder();
myBuider.Append( "abcdefgh ");
myBuider.Append( "hijklmn ");
...

用的时候
myBuilder.ToString();
------解决方案--------------------
string s = @ "abcdefghijklmnabcdefghijklmnabcd
efghijklmnabcdefghijklmn ";

------解决方案--------------------
楼上定义有点问题,会把空格,回车换行等一起赋值给字符串了,除非像sql语法那样不分空格回车换行才可以提高可读性
string s = @ "abcdefghijklmnabcdefghijklmnabcd
efghijklmnabcdefghijklmn ";

如果是其它场合,我看还是一行一行加吧。
StringBuilder myBuilder = new StringBuilder();
myBuider.Append( "abcdefgh ");
myBuider.Append( "hijklmn ");
...

用的时候
myBuilder.ToString();