C# 有类似于 Python 的通用换行符的东西吗

Does C# have something similar to Python's universal newlines

Python's file objects can now support end of line conventions other than the one followed by the platform on which Python is running. Opening a file with the mode 'U' or 'rU' will open a file for reading in universal newline mode. All three line ending conventions will be translated to a "\n" in the strings returned by the various file methods such as read() and readline().

https://docs.python.org/2.3/whatsnew/node7.html

在Python3中,通用换行符是打开文本文件的默认模式。也就是说,当打开文本文件时,我根本不必关心行结束约定。

我们在 C# 中也有这样的便利功能吗?

StreamReader.ReadLine 这样做:

A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"), or a carriage return immediately followed by a line feed ("\r\n"). The string that is returned does not contain the terminating carriage return or line feed.

从文件中读取行的便捷方法,例如 File.ReadLinesFile.ReadAllLines,在底层使用 StreamReader

我不知道有什么方法可以将文件中的多行作为字符串读取,但是会默默地用规范化的 \n 替换所有行结束字符。 StreamReader.ReadToEnd() 不会以这种方式处理它读取的文本。