File.ReadAllLines()和File.ReadAllText()有什么区别?

时间:2022-01-11 03:40:29

What is the difference between File.ReadAllLines() and File.ReadAllText()?

File.ReadAllLines()和File.ReadAllText()有什么区别?

3 个解决方案

#1


74  

ReadAllLines returns an array of strings. Each string contains a single line of the file.

ReadAllLines返回一个字符串数组。每个字符串包含一行文件。

ReadAllText returns a single string containing all the lines of the file.

ReadAllText返回包含文件所有行的单个字符串。

#2


12  

File.ReadAllText() returns one big string containing all the content of the file while File.ReadAllLines() returns string array of lines in the file.

File.ReadAllText()返回一个包含文件所有内容的大字符串,而File.ReadAllLines()返回文件中的字符串数组。

Keep in mind that in case of ReadAllText "The resulting string does not contain the terminating carriage return and/or line feed."

请记住,在ReadAllText的情况下“结果字符串不包含终止回车符和/或换行符。”

More details are available at remarks section of File.ReadAllText Method and File.ReadAllLines Method.

File.ReadAllText方法和File.ReadAllLines方法的备注部分提供了更多详细信息。

#3


6  

ReadAllText reads it all in as one string, ReadAllLines reads it in as a StringArray.

ReadAllText将其作为一个字符串读取,ReadAllLines将其作为StringArray读取。

#1


74  

ReadAllLines returns an array of strings. Each string contains a single line of the file.

ReadAllLines返回一个字符串数组。每个字符串包含一行文件。

ReadAllText returns a single string containing all the lines of the file.

ReadAllText返回包含文件所有行的单个字符串。

#2


12  

File.ReadAllText() returns one big string containing all the content of the file while File.ReadAllLines() returns string array of lines in the file.

File.ReadAllText()返回一个包含文件所有内容的大字符串,而File.ReadAllLines()返回文件中的字符串数组。

Keep in mind that in case of ReadAllText "The resulting string does not contain the terminating carriage return and/or line feed."

请记住,在ReadAllText的情况下“结果字符串不包含终止回车符和/或换行符。”

More details are available at remarks section of File.ReadAllText Method and File.ReadAllLines Method.

File.ReadAllText方法和File.ReadAllLines方法的备注部分提供了更多详细信息。

#3


6  

ReadAllText reads it all in as one string, ReadAllLines reads it in as a StringArray.

ReadAllText将其作为一个字符串读取,ReadAllLines将其作为StringArray读取。