Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else?
It is not a bug. CRLF is the default for the Environment.NewLine in Windows: a 'string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.'
How can we explain this?
It probably results from the way you are outputting the string values to a file. If you use a method that adds new lines (e.g., such as WriteAllLines()) does, then there will automatically be a CRLF at the end of each value you write.
For instance, if we can run the following program,.
string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); Then we will produceIt produces two output files. The one on the left used WriteAllLines to write four lines. The one on the right used WriteAllText() and did not write any new lines.
AllIn both, all of the content outside of parentheses is independent of your code. That is, the CRLF symbols are part of writing a line in the call to WriteAllLines.
