What is the difference between File.ReadAllLines()
and File.ReadAllText()
?
Explanation: The difference between the method foreach and the method readlines is that the method foreach is associated with a block. However, unlike the method readlines, the method foreach does not return an array. 9.
The ReadLines and ReadAllLines methods differ as follows: When you use ReadLines, you can start enumerating the collection of strings before the whole collection is returned; when you use ReadAllLines, you must wait for the whole array of strings be returned before you can access the array.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With