While testing some snippets in dotnetfiddle.net I noticed strange phenomenom.
If verbatim string literal (string starts @"
) contains newline in it, compiler emits newline as \n
in output string instead of \r\n
. (for example Environment.NewLine
produces \r\n
in all cases).
Example code below can also be found in https://dotnetfiddle.net/53qGTM:
string verbatimString = @"L1
L2";
string normalString = @"L1" + Environment.NewLine + "L2";
Console.WriteLine("=====Verbatim=====");
foreach (char c in verbatimString)
{
Console.WriteLine("ascii:" + (int)c + ", char:" + c);
}
Console.WriteLine("=====Normal=====");
foreach (char c in normalString)
{
Console.WriteLine("ascii:" + (int)c + ", char:" + c);
}
output:
=====Verbatim=====
ascii:76, char:L
ascii:49, char:1
ascii:10, char:
ascii:76, char:L
ascii:50, char:2
=====Normal=====
ascii:76, char:L
ascii:49, char:1
ascii:13, char:
ascii:10, char:
ascii:76, char:L
ascii:50, char:2
When compiling same code in Visual Studio, newline is correctly \r\n
in both cases. It seems as bug in dotnetfiddle-compiler, is it so?
While making some investigations I also made an assumption what's going on and I'll also make first answer to this question as recommended.