ant*_*ony 193
取决于平台.在Windows上它实际上是"\ r \n".
来自MSDN:
对于非Unix平台包含"\ r \n"的字符串,或者对于Unix平台包含"\n"的字符串.
alo*_*ica 146
Environment.NewLine从源代码中精确实现:
.NET 4.6.1中的实现:
/*===================================NewLine====================================
**Action: A property which returns the appropriate newline string for the given
** platform.
**Returns: \r\n on Win32.
**Arguments: None.
**Exceptions: None.
==============================================================================*/
public static String NewLine {
get {
Contract.Ensures(Contract.Result<String>() != null);
return "\r\n";
}
}
Run Code Online (Sandbox Code Playgroud)
.NET Core中的实现:
/*===================================NewLine====================================
**Action: A property which returns the appropriate newline string for the
** given platform.
**Returns: \r\n on Win32.
**Arguments: None.
**Exceptions: None.
==============================================================================*/
public static String NewLine {
get {
Contract.Ensures(Contract.Result() != null);
#if !PLATFORM_UNIX
return "\r\n";
#else
return "\n";
#endif // !PLATFORM_UNIX
}
}
Run Code Online (Sandbox Code Playgroud)
来源(中System.Private.CoreLib)
public static string NewLine => "\r\n";
Run Code Online (Sandbox Code Playgroud)
来源(中System.Runtime.Extensions)
P D*_*ddy 69
正如其他人所提到的,Environment.NewLine返回一个特定于平台的字符串,用于开始一个新行,该行应该是:
"\r\n" (\ u000D\u000A)适用于Windows"\n" (\ u000A)用于Unix"\r" (\ u000D)for Mac(如果存在此类实现)请注意,写入控制台时,不一定要使用Environment.NewLine."\n"如有必要,控制台流将转换为适当的新行序列.
| 归档时间: |
|
| 查看次数: |
303154 次 |
| 最近记录: |