-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Milestone
Description
Hi.
I've run into some puzzling behaviour with StreamReader.ReadLine that appears to deviate that described in the documentation. According to these docs, StreamReader.ReadLine should return null if the end of the input stream is reached (before a line-ending sequence is encountered, I assume, although that assumption may be the source of the problem). But that's not the behaviour I'm seeing.
A simple repro:
byte[] data = Encoding.ASCII.GetBytes("Hello world"); // No newline
using (MemoryStream dataStream = new MemoryStream(data))
using (StreamReader dataReader = new StreamReader(dataStream, Encoding.ASCII, detectEncodingFromByteOrderMarks: false, bufferSize: 5))
{
string line = dataReader.ReadLine();
if (line == null)
Console.WriteLine("No line.");
else
Console.WriteLine($"Line: '{line}'.");
}Am I reading the documentation correctly, or is the implication that ReadLine will return whatever it has even if it has never encountered a new-line sequence?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels