Modernize C# code snippets - System/P*, System/R* - #12969
Open
gewarren wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes a set of C# snippet sources under System/P*, System/R* to align with the ongoing repo effort to update samples for current C#/.NET style (Issue #12713).
Changes:
- Replaced legacy formatting patterns (
string.Format, composite formatting) with string interpolation and simplified output formatting. - Adopted modern C# syntax (target-typed
new(), expression-bodied members, simplified array declarations, whitespace cleanup). - Normalized indentation and minor code-style cleanups across affected snippet files.
Reviewed changes
Copilot reviewed 23 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| snippets/csharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.cs | Removes unused using and modernizes members/printing with target-typed new() and interpolation. |
| snippets/csharp/System/ReadOnlySpanT/GetPinnableReference/getpinnablereference1.cs | Simplifies helper method to an expression-bodied member; preserves unsafe sample intent. |
| snippets/csharp/System/Random/Overview/uniquearray1.cs | Updates ToString() and output formatting to interpolation; target-typed new(). |
| snippets/csharp/System/Random/Overview/unique.cs | Updates Console.WriteLine to interpolation for generated values. |
| snippets/csharp/System/Random/Overview/threadsafeex2.cs | Uses target-typed new() and interpolated output strings in async/threading sample. |
| snippets/csharp/System/Random/Overview/threadsafeex1.cs | Uses target-typed new() in constructor initialization. |
| snippets/csharp/System/Random/Overview/Random2.cs | Converts composite format writes (with alignment) to interpolated writes. |
| snippets/csharp/System/Random/Overview/Next2.cs | Reindents and converts aligned writes to interpolated writes. |
| snippets/csharp/System/Random/Overview/next.cs | Cleans up whitespace/indentation in sample entrypoint. |
| snippets/csharp/System/Random/Overview/long1.cs | Converts header/row composite formatting to interpolated strings with alignment. |
| snippets/csharp/System/Random/Overview/doublerange3.cs | Converts composite formatting to a single interpolated output line. |
| snippets/csharp/System/Random/Overview/doublerange1.cs | Converts header/row composite formatting to interpolated strings with alignment. |
| snippets/csharp/System/Random/Overview/booleans2.cs | Consolidates output formatting and converts local function to expression-bodied. |
| snippets/csharp/System/Random/Overview/booleans1.cs | Consolidates output formatting; modernizes ctor and boolean generator method bodies. |
| snippets/csharp/System/Random/NextDouble/nextdouble1.cs | Reindents and partially modernizes declarations/spacing while keeping sample structure. |
| snippets/csharp/System/Random/NextBytes/source.cs | Uses built-in aliases (byte) and target-typed new(); converts output to interpolation. |
| snippets/csharp/System/Random/Next/sample.cs | Converts overrides and output formatting to expression-bodied members/interpolation; cleans up array declarations. |
| snippets/csharp/System/Random/.ctor/ctor4.cs | Reindents and modernizes Random initialization and output formatting in ctor sample. |
| snippets/csharp/System/Random/.ctor/ctor1.cs | Reindents and modernizes Random initialization and output formatting in ctor sample. |
| snippets/csharp/System/Random/.ctor/ctor.cs | Modernizes loops, initialization, and some output formatting while preserving sample narrative. |
| snippets/csharp/System/PredicateT/Overview/predicateex2.cs | Converts predicate method to expression-bodied and output to interpolation; reindents. |
| snippets/csharp/System/PredicateT/Overview/predicateex1.cs | Converts output to interpolation and reindents sample. |
| snippets/csharp/System/PredicateT/Overview/predicate1.cs | Modernizes properties to expression-bodied, target-typed new(), and interpolated output. |
| snippets/csharp/System/PlatformID/Overview/pid.cs | Reindents switch sample and normalizes snippet marker formatting. |
| snippets/csharp/System/ParamArrayAttribute/Overview/Example.cs | Modernizes members and exception formatting; updates string.IsNullOrEmpty usage and general style. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
BillWagner
approved these changes
Aug 12, 2026
BillWagner
left a comment
Member
There was a problem hiding this comment.
Once again, this looks great, with a couple optional comments.
Co-authored-by: Bill Wagner <wiwagn@microsoft.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.
Contributes to #12713.
Internal previews
Toggle expand/collapse