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

C#File.Netfile.readalllines

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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.

Solution 3 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioniTaybView Question on Stackoverflow
Solution 1 - C#LukeHView Answer on Stackoverflow
Solution 2 - C#GiorgiView Answer on Stackoverflow
Solution 3 - C#Hans OlssonView Answer on Stackoverflow