Skip to content

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

Merged
gewarren merged 6 commits intomainfrom
copilot/update-streamreader-documentation
Apr 24, 2026
Merged

Document trailing newline behavior for ReadLine and ReadAllLines/ReadLines APIs#12493
gewarren merged 6 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

Comment thread xml/System.IO/File.xml Outdated
Copilot AI requested a review from gewarren April 13, 2026 20:51
@gewarren
Copy link
Copy Markdown
Contributor

I will work on the merge conflicts...

@gewarren gewarren marked this pull request as ready for review April 13, 2026 21:12
@gewarren gewarren requested a review from a team as a code owner April 13, 2026 21:12
Copilot AI review requested due to automatic review settings April 13, 2026 21:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR documents a subtle but important behavior of the .NET line-reading APIs: a trailing newline at the end of the input does not produce an extra empty string/line in the returned results, reducing confusion for developers reading streams, strings, and files.

Changes:

  • Added a note to ReadLine remarks for TextReader, StringReader, and StreamReader clarifying trailing-newline behavior.
  • Added the same clarification to File.ReadAllLines (both overloads) and File.ReadLines (both overloads), including examples.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
xml/System.IO/TextReader.xml Adds trailing-newline behavior note to TextReader.ReadLine remarks.
xml/System.IO/StringReader.xml Adds trailing-newline behavior note to StringReader.ReadLine remarks and removes extra blank lines before Examples.
xml/System.IO/StreamReader.xml Adds trailing-newline behavior note to StreamReader.ReadLine remarks.
xml/System.IO/File.xml Adds trailing-newline behavior notes to ReadAllLines and ReadLines remarks (including encoding overloads), plus minor formatting adjustments around Examples.

Comment thread xml/System.IO/File.xml Outdated
Comment thread xml/System.IO/File.xml Outdated
Comment thread xml/System.IO/TextReader.xml Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gewarren gewarren enabled auto-merge (squash) April 24, 2026 21:46
@gewarren gewarren merged commit 5f0cd21 into main Apr 24, 2026
6 checks passed
@gewarren gewarren deleted the copilot/update-streamreader-documentation branch April 24, 2026 22:06
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

4 participants