Document trailing newline behavior for ReadLine and ReadAllLines/ReadLines APIs#12493
Merged
Document trailing newline behavior for ReadLine and ReadAllLines/ReadLines APIs#12493
Conversation
… 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>
…eadLine docs 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
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
gewarren
reviewed
Apr 13, 2026
…ocumentation Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/916a4b61-9a5e-44f6-a396-cf4dfe84056d Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
gewarren
approved these changes
Apr 13, 2026
Contributor
|
I will work on the merge conflicts... |
Contributor
There was a problem hiding this comment.
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
ReadLineremarks forTextReader,StringReader, andStreamReaderclarifying trailing-newline behavior. - Added the same clarification to
File.ReadAllLines(both overloads) andFile.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. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
## Remarkssection of each:StreamReader.ReadLineTextReader.ReadLineStringReader.ReadLineFile.ReadAllLines(string)/File.ReadAllLines(string, Encoding)File.ReadLines(string)/File.ReadLines(string, Encoding)Example note added (StreamReader.ReadLine)