string str = @"//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings. \n Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//";
对richTextBox的结果文本是:
//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings. \n Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//
但
string str = @"//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings."+" \n" + @" Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//";
对richTextBox的结果文本是:
//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings.
Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//
答案 0 :(得分:3)
在您的中心字符串之前没有文字@" \ n" 等价物是
string str = @"//
// Use a new char[] array of two characters (\r and \n) to break
// lines from into separate strings."+ @" \n" + @" Use RemoveEmptyEntries
// to make sure no empty strings get put in the string array.
//";
\是普通字符串中的转义字符,但字符串文字完全按原样使用内容,除非是"被转义为""
答案 1 :(得分:1)
因为" \ n"之前没有@在你的第二个例子。 @(逐字字符串文字)之后的任何转义序列都将被忽略。在你的第一个例子中,它被忽略但不在第二个例子中。
看看这个: http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx