From 5ef0e0024291a84803513fbb8154484320bfa3b7 Mon Sep 17 00:00:00 2001 From: jontho-microsoft-com <45051489+jontho-microsoft-com@users.noreply.github.com> Date: Wed, 12 Apr 2023 15:28:20 -0700 Subject: [PATCH] Update strmreader read2.cs .NET source code clearly shows Read() may not return a fixed number of characters, but only what's currently available on the stream. ReadBlock returns the stated number of characters and only returns fewer if end of stream --- snippets/csharp/System.IO/StreamReader/Read/strmreader read2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/csharp/System.IO/StreamReader/Read/strmreader read2.cs b/snippets/csharp/System.IO/StreamReader/Read/strmreader read2.cs index 8294a2c88a1..5487c1777a3 100644 --- a/snippets/csharp/System.IO/StreamReader/Read/strmreader read2.cs +++ b/snippets/csharp/System.IO/StreamReader/Read/strmreader read2.cs @@ -32,7 +32,7 @@ public static void Main() while (sr.Peek() >= 0) { c = new char[5]; - sr.Read(c, 0, c.Length); + sr.ReadBlock(c, 0, c.Length); //The output will look odd, because //only five characters are read at a time. Console.WriteLine(c);