From c25c30a18212d66d729fcaa716d901b29d0738f4 Mon Sep 17 00:00:00 2001 From: Ivan Peshterski Date: Sun, 8 Mar 2026 23:06:23 +0200 Subject: [PATCH 1/2] Improve sample: safer argument parsing and clearer delay --- docs/core/docker/snippets/App/Program.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/core/docker/snippets/App/Program.cs b/docs/core/docker/snippets/App/Program.cs index 82e9ce0b61b99..58cf2ea5e871f 100644 --- a/docs/core/docker/snippets/App/Program.cs +++ b/docs/core/docker/snippets/App/Program.cs @@ -1,9 +1,16 @@ var counter = 0; -var max = args.Length is not 0 ? Convert.ToInt32(args[0]) : -1; -while (max is -1 || counter < max) +// If a number is passed as a command-line argument, +// it will be used as the maximum counter value. +var max = args.Length > 0 && int.TryParse(args[0], out var parsedMax) + ? parsedMax + : -1; + +// Run indefinitely if no max value is provided +while (max == -1 || counter < max) { Console.WriteLine($"Counter: {++counter}"); - await Task.Delay(TimeSpan.FromMilliseconds(1_000)); + // Wait for one second between iterations + await Task.Delay(TimeSpan.FromSeconds(1)); } From 462f7a76be5fbe0c4e8f1a900adfd10c53b95581 Mon Sep 17 00:00:00 2001 From: Ivan Peshterski Date: Mon, 9 Mar 2026 00:24:04 +0200 Subject: [PATCH 2/2] Improve readability of console sample code --- .../csharp/ShowCase/Program.cs | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/Program.cs b/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/Program.cs index e3f9b32b90e7a..a1d2363e5dd08 100644 --- a/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/Program.cs +++ b/docs/core/tutorials/snippets/create-class-library/csharp/ShowCase/Program.cs @@ -1,30 +1,42 @@ using System; using UtilityLibraries; -int row = 0; +const int EntriesPerPage = 7; -do +int entryCount = 0; + +ResetConsole(); + +while (true) { - if (row == 0 || row >= 25) + string? input = Console.ReadLine(); + + if (string.IsNullOrWhiteSpace(input)) + break; + + if (entryCount >= EntriesPerPage) + { + Console.WriteLine("Press any key to continue..."); + Console.ReadKey(true); ResetConsole(); + entryCount = 0; + } + + string result = input.StartsWithUpper() ? "Yes" : "No"; + + Console.WriteLine($"Input: {input}"); + Console.WriteLine($"{"Begins with uppercase?",30}: {result}"); + Console.WriteLine(); + + entryCount++; +} - string? input = Console.ReadLine(); - if (string.IsNullOrWhiteSpace(input)) break; - Console.WriteLine($"Input: {input} {"Begins with uppercase? ",30}: " + - $"{(input.StartsWithUpper() ? "Yes" : "No")}{Environment.NewLine}"); - row += 3; -} while (true); return; -// Declare a ResetConsole local method void ResetConsole() { - if (row > 0) - { - Console.WriteLine("Press any key to continue..."); - Console.ReadKey(); - } Console.Clear(); - Console.WriteLine($"{Environment.NewLine}Press only to exit; otherwise, enter a string and press :{Environment.NewLine}"); - row = 3; + Console.WriteLine(); + Console.WriteLine("Press only to exit; otherwise, enter a string and press :"); + Console.WriteLine(); } \ No newline at end of file