Modernize C# snippets - System/E* - #12965
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR contributes to issue #12713 by modernizing a large set of C# reference snippets under snippets/csharp/System/* (notably System.Exception, System.Environment, System.Enum, System.Console, and System.Char*) to be more consistent with modern C# style and .NET 10-era guidance.
Changes:
- Updated many snippets to modern C# syntax (string interpolation, target-typed
new, expression-bodied members, explicit built-in type keywords likestring/object/char, and consistent brace/indentation). - Refreshed output formatting and loop/exception-handling layouts for readability and consistency.
- Minor refactors to reduce verbosity in common patterns (constructors, simple methods, event invocations).
Reviewed changes
Copilot reviewed 157 out of 168 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| snippets/csharp/System/Exception/ToString/ToStringEx1.cs | Modernize formatting and output string construction. |
| snippets/csharp/System/Exception/Overview/usageerrors2.cs | Modernize property/accessor style and object initialization. |
| snippets/csharp/System/Exception/Overview/usageerrors1.cs | Modernize property/accessor style and object initialization. |
| snippets/csharp/System/Exception/Overview/rethrow1.cs | Modernize string/type usage and formatting. |
| snippets/csharp/System/Exception/Overview/primenumbergenerator.cs | Modernize collections initialization and method bodies. |
| snippets/csharp/System/Exception/Overview/notprimeexception.cs | Modernize exception constructors and property syntax. |
| snippets/csharp/System/Exception/Overview/example.cs | Modernize construction/printing style. |
| snippets/csharp/System/Exception/Overview/catchexception.cs | Formatting normalization and minor syntax updates. |
| snippets/csharp/System/Exception/InnerException/innerex.cs | Modernize object creation, formatting, and method bodies. |
| snippets/csharp/System/Exception/HResult/hresult.cs | Modernize formatting and reduce verbosity. |
| snippets/csharp/System/Exception/HelpLink/properties.cs | Modernize formatting, constructors, and output strings. |
| snippets/csharp/System/Exception/GetBaseException/getbaseexc.cs | Modernize formatting and method calls. |
| snippets/csharp/System/Exception/Data/data.cs | Modernize formatting and switch to interpolated output. |
| snippets/csharp/System/Exception/.ctor/newsi.cs | Modernize formatting and constructors/output strings. |
| snippets/csharp/System/Exception/.ctor/news.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Exception/.ctor/new.cs | Modernize formatting and output strings. |
| snippets/csharp/System/EventArgs/Overview/programwithdelegate.cs | Modernize output strings and simplify members. |
| snippets/csharp/System/EventArgs/Overview/programwithdata.cs | Modernize output strings and simplify members. |
| snippets/csharp/System/EventArgs/Overview/programtruncated.cs | Simplify handler to expression-bodied member. |
| snippets/csharp/System/EventArgs/Overview/programnodata.cs | Simplify members with expression-bodied syntax. |
| snippets/csharp/System/Environment+SpecialFolder/Overview/getfolderpath.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/WorkingSet/workingset.cs | Convert to expression-bodied Main. |
| snippets/csharp/System/Environment/Version/version.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/UserName/username.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/UserInteractive/userinteractive.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/SystemDirectory/systemdirectory.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/StackTrace/stacktrace.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/ProcessorCount/pc.cs | Modernize formatting and reduce verbosity. |
| snippets/csharp/System/Environment/Overview/env0.cs | Modernize output strings across the sample. |
| snippets/csharp/System/Environment/MachineName/machinename.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/GetLogicalDrives/getlogicaldrives.cs | Modernize type keywords and output strings. |
| snippets/csharp/System/Environment/GetEnvironmentVariables/getenvironmentvariables.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/GetEnvironmentVariable/gsev.cs | Remove unused usings and normalize foreach typing/formatting. |
| snippets/csharp/System/Environment/GetEnvironmentVariable/getenvironmentvariableex1.cs | Modernize formatting and loop style. |
| snippets/csharp/System/Environment/GetCommandLineArgs/getcommandlineargs.cs | Switch to interpolated output. |
| snippets/csharp/System/Environment/FailFast/ff.cs | Formatting normalization. |
| snippets/csharp/System/Environment/ExitCode/double1.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/ExitCode/double.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Environment/CurrentDirectory/Vars1.cs | Modernize object creation and formatting. |
| snippets/csharp/System/Environment/CurrentDirectory/environmentsample.cs | Remove unused usings and modernize method bodies. |
| snippets/csharp/System/Environment/CommandLine/commandline.cs | Switch to interpolated output and normalize formatting. |
| snippets/csharp/System/Enum/TryParseTEnum/tryparse2.cs | Modernize enum spacing and output strings. |
| snippets/csharp/System/Enum/TryParseTEnum/tryparse1.cs | Modernize enum spacing and output strings. |
| snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs | Formatting normalization. |
| snippets/csharp/System/Enum/ToString/tostr.cs | Modernize enum spacing and output strings. |
| snippets/csharp/System/Enum/ToString/source.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Enum/Parse/ParseExample2.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Enum/Parse/ParseExample1.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Enum/Parse/EnumParse.cs | Modernize parsing/casting formatting. |
| snippets/csharp/System/Enum/Overview/Extensions.cs | Convert simple method to expression-bodied. |
| snippets/csharp/System/Enum/Overview/EnumMain.cs | Normalize formatting and output strings. |
| snippets/csharp/System/Enum/Overview/classiterate.cs | Normalize file header/foreach typing. |
| snippets/csharp/System/Enum/Overview/classformat1.cs | Normalize foreach typing. |
| snippets/csharp/System/Enum/Overview/classconversion2.cs | Make converted value explicitly object. |
| snippets/csharp/System/Enum/Overview/classconversion1.cs | Normalize type keywords and foreach typing. |
| snippets/csharp/System/Enum/Overview/class2.cs | Use target-typed new(). |
| snippets/csharp/System/Enum/Overview/class1.cs | Modernize enum spacing and Main formatting. |
| snippets/csharp/System/Enum/IsDefined/isdefined2.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Enum/IsDefined/isdefined1.cs | Modernize formatting and output strings. |
| snippets/csharp/System/Enum/HasFlag/hasflag1.cs | Normalize enum formatting and output strings. |
| snippets/csharp/System/Enum/HasFlag/hasflag0.cs | Normalize output strings and formatting. |
| snippets/csharp/System/Enum/GetValues/getvalues1.cs | Normalize foreach typing and braces. |
| snippets/csharp/System/Enum/GetValues/getvalues_reflectiononly.cs | Normalize loops, output strings, and enum formatting. |
| snippets/csharp/System/Enum/GetValues/EnumGetValues.cs | Normalize formatting and foreach typing. |
| snippets/csharp/System/Enum/GetUnderlyingType/getunderlyingtype1.cs | Switch to interpolated/aligned output. |
| snippets/csharp/System/Enum/GetNames/getnames1.cs | Normalize foreach typing and braces. |
| snippets/csharp/System/Enum/GetNames/EnumGetNames.cs | Normalize formatting and foreach typing. |
| snippets/csharp/System/Enum/GetName/EnumGetName.cs | Normalize formatting and output strings. |
| snippets/csharp/System/Enum/Format/EnumFormat.cs | Switch to interpolated output and normalize braces. |
| snippets/csharp/System/Enum/Equals/enumequals1.cs | Normalize enum formatting and braces. |
| snippets/csharp/System/Enum/Equals/EnumEquals.cs | Switch to interpolated output strings. |
| snippets/csharp/System/Enum/CompareTo/EnumCompareTo.cs | Switch to interpolated output strings and normalize formatting. |
| snippets/csharp/System/EntryPointNotFoundException/Overview/stringutilities.cs | Convert to expression-bodied method and interpolated string. |
| snippets/csharp/System/EntryPointNotFoundException/Overview/nofunction1.cs | Normalize formatting and output strings. |
| snippets/csharp/System/EntryPointNotFoundException/Overview/mangle2.cs | Convert to expression-bodied Main. |
| snippets/csharp/System/EntryPointNotFoundException/Overview/mangle1.cs | Convert to expression-bodied Main. |
| snippets/csharp/System/EntryPointNotFoundException/Overview/importassembly1.cs | Use string and expression-bodied Main. |
| snippets/csharp/System/EntryPointNotFoundException/Overview/fiximportassembly1.cs | Convert to expression-bodied Main. |
| snippets/csharp/System/EntryPointNotFoundException/Overview/badcall1.cs | Normalize signatures/formatting and output strings. |
| snippets/csharp/System/ConsoleKeyInfo/KeyChar/keychar1.cs | Modernize formatting and type keywords. |
| snippets/csharp/System/ConsoleKeyInfo/GetHashCode/hash.cs | Modernize initialization patterns and formatting. |
| snippets/csharp/System/ConsoleKeyInfo/Equals/equals.cs | Modernize initialization patterns and formatting. |
| snippets/csharp/System/ConsoleKey/Overview/ConsoleKey1.cs | Normalize formatting and simplify output building. |
| snippets/csharp/System/Console/WriteLine/WriteLine7.cs | Convert to expression-bodied Main. |
| snippets/csharp/System/Console/WriteLine/WriteLine6.cs | Use target-typed new and normalize loop formatting. |
| snippets/csharp/System/Console/WriteLine/writeline_obj1.cs | Use object[] and explicit foreach typing. |
| snippets/csharp/System/Console/WriteLine/writeline_boolean1.cs | Use target-typed new and normalize loops. |
| snippets/csharp/System/Console/WriteLine/tipcalc.cs | Normalize keywords and TryParse call. |
| snippets/csharp/System/Console/WriteLine/newline1.cs | Normalize loops/formatting. |
| snippets/csharp/System/Console/Write/WriteParams2.cs | Use built-in type keywords and modern object init. |
| snippets/csharp/System/Console/Write/WriteParams1.cs | Use built-in type keywords and modern object init. |
| snippets/csharp/System/Console/Write/wl.cs | Normalize file header and enum formatting. |
| snippets/csharp/System/Console/Write/reformat.cs | Normalize loop typing and TryParse usage. |
| snippets/csharp/System/Console/WindowLeft/windowleft1.cs | Normalize loops/formatting and output strings. |
| snippets/csharp/System/Console/Title/mytitle.cs | Switch to interpolated output strings. |
| snippets/csharp/System/Console/SetWindowSize/sws.cs | Normalize formatting and arithmetic spacing. |
| snippets/csharp/System/Console/SetOut/source.cs | Normalize formatting and use target-typed new. |
| snippets/csharp/System/Console/SetError/SetError1.cs | Remove unused using and switch to interpolated output strings. |
| snippets/csharp/System/Console/ReadLine/ReadLineSimple.cs | Normalize formatting. |
| snippets/csharp/System/Console/ReadLine/ReadLine3.cs | Normalize formatting and output strings. |
| snippets/csharp/System/Console/ReadLine/ReadLine2.cs | Normalize formatting. |
| snippets/csharp/System/Console/ReadKey/rkbool.cs | Normalize formatting and output strings. |
| snippets/csharp/System/Console/ReadKey/rk.cs | Normalize formatting. |
| snippets/csharp/System/Console/ReadKey/ReadKey2.cs | Use interpolated/conditional output and normalize loops. |
| snippets/csharp/System/Console/ReadKey/ReadKey1.cs | Use interpolated/conditional output and normalize loops. |
| snippets/csharp/System/Console/Read/read.cs | Normalize formatting and type keywords. |
| snippets/csharp/System/Console/Overview/unicode1.cs | Normalize loops/formatting and output strings. |
| snippets/csharp/System/Console/Overview/source.cs | Normalize file header and braces. |
| snippets/csharp/System/Console/Overview/normalize1.cs | Remove unused using and modernize construction. |
| snippets/csharp/System/Console/Overview/fontlink1.cs | Normalize control-flow formatting and spacing. |
| snippets/csharp/System/Console/Out/out1.cs | Use target-typed new and object initializer. |
| snippets/csharp/System/Console/OpenStandardOutput/inserttabs.cs | Use object initializer for AutoFlush. |
| snippets/csharp/System/Console/OpenStandardInput/decode.cs | Normalize braces/formatting. |
| snippets/csharp/System/Console/KeyAvailable/ka.cs | Normalize loops/formatting and output strings. |
| snippets/csharp/System/Console/In/consolein.cs | Normalize braces/formatting and output strings. |
| snippets/csharp/System/Console/Error/viewtextfile.cs | Use built-in type keywords and modern resource creation. |
| snippets/csharp/System/Console/Error/expandtabsex.cs | Normalize try/catch formatting and output strings. |
| snippets/csharp/System/Console/Error/error1.cs | Normalize loops and output strings. |
| snippets/csharp/System/Console/CursorVisible/vis.cs | Normalize loops/formatting and type keywords. |
| snippets/csharp/System/Console/CursorSize/csize.cs | Normalize formatting and spacing. |
| snippets/csharp/System/Console/Clear/lts.cs | Normalize formatting and spacing. |
| snippets/csharp/System/Console/CancelKeyPress/ckp.cs | Modernize event handler subscription and output strings. |
| snippets/csharp/System/Console/BufferHeight/hw.cs | Switch to interpolated output strings. |
| snippets/csharp/System/Console/Beep/beep.cs | Use built-in type keywords and interpolated output. |
| snippets/csharp/System/Console/Beep/b2.cs | Normalize formatting, enums, and properties. |
| snippets/csharp/System/Console/BackgroundColor/foregroundcolor3.cs | Normalize loops/formatting and output strings. |
| snippets/csharp/System/Console/BackgroundColor/Example2.cs | Normalize control-flow formatting. |
| snippets/csharp/System/Console/BackgroundColor/backgroundcolor1.cs | Normalize formatting and use string keyword. |
| snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs | Normalize formatting and output strings. |
| snippets/csharp/System/Char/ToUpper/toupper5.cs | Normalize loops/formatting and built-in keywords. |
| snippets/csharp/System/Char/ToUpper/toupper1.cs | Normalize foreach typing and output formatting. |
| snippets/csharp/System/Char/ToString/tostring.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/ToLower/tolower.cs | Remove unused using and normalize formatting. |
| snippets/csharp/System/Char/Parse/parse.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/Overview/textelements2a.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/Overview/textelements2.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/Overview/surrogate1.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/Overview/grapheme1.cs | Use target-typed new and collection expression. |
| snippets/csharp/System/Char/Overview/GetUnicodeCategory3.cs | Remove unused using and normalize loops/keywords. |
| snippets/csharp/System/Char/Overview/charstructure.cs | Normalize to char static APIs. |
| snippets/csharp/System/Char/IsWhiteSpace/iswhitespace.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsSymbol/issymbol.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsSurrogate/issurrogate.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsSeparator/isseparator1.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsSeparator/isseparator.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsPunctuation/ispunctuation.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsNumber/isnumber1.cs | Normalize formatting and switch to interpolated output. |
| snippets/csharp/System/Char/IsNumber/isnumber.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsLower/islower.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsLetterOrDigit/isletterordigit.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsLetter/isletter.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsHighSurrogate/sur.cs | Normalize formatting and output strings. |
| snippets/csharp/System/Char/IsDigit/isdigit.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/IsControl/IsControl2.cs | Switch to interpolated output and normalize formatting. |
| snippets/csharp/System/Char/IsControl/IsControl1.cs | Normalize formatting and switch to interpolated output. |
| snippets/csharp/System/Char/IsControl/iscontrol.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/GetUnicodeCategory/getunicodecategory.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/GetNumericValue/getnumericvalue.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/Equals/equals.cs | Normalize formatting and built-in keyword usage. |
| snippets/csharp/System/Char/CompareTo/compareto.cs | Normalize formatting and built-in keyword usage. |
💡 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>
This reverts commit 7d91044.
…api-docs into modernize-code-system-e
wadepickett
approved these changes
Aug 11, 2026
wadepickett
left a comment
Contributor
There was a problem hiding this comment.
@gewarren: Approved: Looks good to me. I couldn't spot any issues.
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
Note
This table shows the first 30 preview links (sorted alphabetically by file path) found in the OPS build report. For the full list, select OpenPublishing.Build Details within checks.