Is there any way to figure out what .NET is using as its “default line terminator”? For example, documentation for StringBuilder.AppendLine(String) says it “Appends a copy of the specified string followed by the default line terminator…”. Several text-related classes in .NET refer to the same concept.
Is there any way to programmatically figure out what is being used as the line terminator (at runtime)? Or is it safe to assume that it will always be “\r\n” for a Windows machine? I’d rather not hard-code that value into my code if I can avoid it.
StringBuilder.AppendLinewill useEnvironment.NewLine, which is “\r\n” for non-Unix platforms and “\n” for Unix platforms.It will always be “
\r\n” for a Windows machine, but you can useEnvironment.NewLinein lieu of a hard-coded value.thanks to @Guffa for verifying this