Skip to content

Document trailing newline behavior for ReadLine and ReadAllLines/ReadLines APIs#12493

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/update-streamreader-documentation
Draft

Document trailing newline behavior for ReadLine and ReadAllLines/ReadLines APIs#12493
Copilot wants to merge 3 commits intomainfrom
copilot/update-streamreader-documentation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

A trailing newline at the end of a stream or file does not produce a final empty string — "foo\nbar\n" and "foo\nbar" both yield the same two lines. This behavior is common but undocumented, making it a source of confusion.

Affected APIs

Added a note to the ## Remarks section of each:

  • StreamReader.ReadLine
  • TextReader.ReadLine
  • StringReader.ReadLine
  • File.ReadAllLines(string) / File.ReadAllLines(string, Encoding)
  • File.ReadLines(string) / File.ReadLines(string, Encoding)

Example note added (StreamReader.ReadLine)

If the stream ends with a newline sequence, no additional empty line is returned. For example, a stream containing "foo\nbar\n" produces the same two lines ("foo" and "bar") as a stream containing "foo\nbar".

Copilot AI and others added 2 commits April 7, 2026 14:03
… TextReader.ReadLine, StringReader.ReadLine, File.ReadAllLines, and File.ReadLines

Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/26046a78-c7a0-46a9-bccb-394eb343d453

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI changed the title [WIP] Document newline treatment in StreamReader.ReadLine Document trailing newline behavior for ReadLine and ReadAllLines/ReadLines APIs Apr 7, 2026
Copilot AI requested a review from adamsitnik April 7, 2026 14:07
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamReader.ReadLine should document how newline at the end of the file is treated

2 participants