Difference between “\n” and Environment.NewLine

2019-01-02 18:05发布

What is the difference between two, if any (with respect to .Net)?

7条回答
墨雨无痕
2楼-- · 2019-01-02 18:34

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.

查看更多
登录 后发表回答