博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Environment.NewLine
阅读量:5283 次
发布时间:2019-06-14

本文共 1693 字,大约阅读时间需要 5 分钟。

Answer1

Exact implementation of Environment.NewLine from the source code:

The implementation in .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
() != null); return "\r\n"; } }


The implementation in .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 } }

(in System.Private.CoreLib)

public static string NewLine => "\r\n";

(in System.Runtime.Extensions)

 

 Answer2

As others have mentioned, Environment.NewLine returns a platform-specific string for beginning a new line, which should be:

  • "\r\n" (\u000D\u000A) for Windows
  • "\n" (\u000A) for Unix
  • "\r" (\u000D) for Mac (if such implementation existed)

Note that when writing to the console, Environment.NewLine is not strictly necessary. The console stream will translate "\n" to the appropriate new-line sequence, if necessary.

Just a note, that would be old macs; new (OSX) macs use \n

 

转载于:https://www.cnblogs.com/chucklu/p/10406894.html

你可能感兴趣的文章
sqlserver 行转列、列转行[转]
查看>>
【IScroll深入学习】解决IScroll疑难杂症
查看>>
python 数据类型
查看>>
108-PHP类成员protected和private成员属性不能被查看数值
查看>>
css控制height充满浏览器视口
查看>>
Linux 系统目录结构
查看>>
python学习之 - XML
查看>>
css问题小计
查看>>
Laravel学习笔记(三)数据库 数据库迁移
查看>>
ORACLE查看并修改最大连接数
查看>>
box-flex不均分问题
查看>>
Python--GIL 详解
查看>>
Oracle数据导入Mysql中
查看>>
BZOJ-4424 &&CodeForces-19E Fairy DP+dfs (Link-Cut-Tree可A)
查看>>
MongoDB学习笔记——聚合操作之group,distinct,count
查看>>
大道至简读后感(第四章)
查看>>
IDA IDC Tutorials: Additional Auto-Commenting
查看>>
k8s-存储卷1-十二
查看>>
在Android中Intent的概念及应用(二)——Intent过滤器相关选项
查看>>
前端面试题(4)iframe有哪些优点?iframe缺点是什么?
查看>>