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

孤者浪人 提交于 2019-11-26 19:58:32

问题


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


回答1:


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

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




回答2:


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

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

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




回答3:


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



来源:https://stackoverflow.com/questions/2965497/what-is-the-difference-between-file-readalllines-and-file-readalltext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!