As per subject...
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
\n is the line break used by Unix(-like) systems, \r\n is used by windows. This has nothing to do with C#.
Basically comes down to Windows standard: \r\n and Unix based systems using: \n
http://en.wikipedia.org/wiki/Newline
\n = LF (Line Feed) // Used as a new line character in Unix
\r = CR (Carriage Return) // Used as a new line character in Mac
\r\n = CR + LF // Used as a new line character in Windows
(char)13 = \r = CR
Environment.NewLine = any of the above code based on the operating system
// .Net provides the Environment class which provides many data based on Operating Systems, so if the application is built in Windows, and you use CR + LF ("\n\r" instead of Environment.NewLine) as new line character in your strings, and then MS creates a VM for running .Net applications in Unix, then there will be problem. So, you should always use Environment.NewLine when you want a new line character. Now you need not to care about operating system.
It's about how operating system recognize line ends.
Morale: if you are developing for windows, stick to \r\n. Or even better, use C# string functions to deal with strings which already consider line endings (WriteLine, and such).
"\n" is just a line feed (Unicode U+000A). This is typically the Unix line separator.
"\r\n" is a carriage return (Unicode U+000D) followed by a line feed (Unicode U+000A). This is typically the Windows line separator.
\n
is Unix,\r
is Mac,\r\n
is Windows.Sometimes it's giving trouble especially when running code cross platform. You can bypass this by using
Environment.NewLine
.Please refer to What is the difference between \r, \n and \r\n ?! for more information. Happy reading