Reputation: 361
just curious about it . i wonder why :
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.
//";
result text to richTextBox was:
//
// 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.
//
but
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.
//";
result text to richTextBox was:
//
// 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.
//
Upvotes: 2
Views: 86
Reputation: 7588
Because there is no @ before the "\n" in you second example. Any escape sequence after @ (verbatim string literal) will be ignored. In your first example it was ignored but not in the second.
Have a look at this: http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
Upvotes: 1
Reputation: 3931
There is no literal @ before your central string " \n" The equivalent would be
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.
//";
\ is an escape character in normal strings, but string literals use the content exactly as is, except in the case of " which is escaped as ""
Upvotes: 3