Skip to content

Improve sample: safer argument parsing and clearer delay#52114

Open
ivanPeshterskii wants to merge 1 commit intodotnet:mainfrom
ivanPeshterskii:main
Open

Improve sample: safer argument parsing and clearer delay#52114
ivanPeshterskii wants to merge 1 commit intodotnet:mainfrom
ivanPeshterskii:main

Conversation

@ivanPeshterskii
Copy link

Description

This PR improves the readability and robustness of the code sample.

Changes made

  • Replaced Convert.ToInt32 with int.TryParse to prevent exceptions when invalid input is provided.
  • Simplified the command-line argument check from args.Length is not 0 to args.Length > 0 for better clarity.
  • Replaced TimeSpan.FromMilliseconds(1_000) with TimeSpan.FromSeconds(1) to improve readability.
  • Slightly refactored the counter increment for better readability in beginner-focused documentation.

These changes make the sample safer and easier to understand, especially for developers who are new to C#.

Motivation

The previous version could throw an exception if a non-numeric argument was passed. Using int.TryParse ensures the example behaves more safely and demonstrates a recommended pattern for parsing user input.

@ivanPeshterskii ivanPeshterskii requested review from a team and adegeo as code owners March 8, 2026 21:08
@dotnetrepoman dotnetrepoman bot added this to the March 2026 milestone Mar 8, 2026
@dotnet-policy-service dotnet-policy-service bot added dotnet-fundamentals/svc dotnet-docker/subsvc community-contribution Indicates PR is created by someone from the .NET community. labels Mar 8, 2026
@gewarren gewarren requested a review from BillWagner March 11, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-docker/subsvc dotnet-fundamentals/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant