这两者之间的区别是什么(如果有的话)?
当前回答
环境的精确实现。来自源代码的换行:
.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";
}
}
源
在。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
}
}
source (in System.Private.CoreLib)
public static string NewLine => "\r\n";
source(在System.Runtime.Extensions中)
其他回答
从医生那里…
包含“\r\n”的字符串 非unix平台,或者字符串 Unix平台包含“\n”。
环境。NewLine将返回运行代码的相应平台的换行符
当你在Mono框架中部署你的代码时,你会发现这非常有用
当您试图显示以“\r\n”分隔的多行消息时,可能会遇到麻烦。
以标准的方式做事,并使用环境总是一个很好的实践。换行符
这取决于平台。在Windows上,它实际上是“\r\n”。
从MSDN:
包含“\r\n”的字符串 非unix平台,或者字符串 Unix平台包含“\n”。
环境的精确实现。来自源代码的换行:
.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";
}
}
源
在。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
}
}
source (in System.Private.CoreLib)
public static string NewLine => "\r\n";
source(在System.Runtime.Extensions中)
推荐文章
- 实体框架核心:在上一个操作完成之前,在此上下文中开始的第二个操作
- 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
- 为什么Visual Studio 2015/2017/2019测试运行器没有发现我的xUnit v2测试
- 如何使用JSON确保字符串是有效的JSON。网
- AppSettings从.config文件中获取值
- 通过HttpClient向REST API发布一个空体
- 如何检查IEnumerable是否为空或空?
- 自动化invokerrequired代码模式
- 没有ListBox。SelectionMode="None",是否有其他方法禁用列表框中的选择?
- 在c#代码中设置WPF文本框的背景颜色
- 在c#中,什么是单子?
- c#和Java中的泛型有什么不同?和模板在c++ ?
- c#线程安全快速(est)计数器
- 如何将此foreach代码转换为Parallel.ForEach?
- 如何在iis7应用程序池中设置。net Framework 4.5版本