Skip to content

Modernize C# snippets (System.Collections) - #13004

Open
gewarren wants to merge 3 commits into
dotnet:mainfrom
gewarren:modernize-code-system-collections
Open

Modernize C# snippets (System.Collections)#13004
gewarren wants to merge 3 commits into
dotnet:mainfrom
gewarren:modernize-code-system-collections

Conversation

@gewarren

@gewarren gewarren commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Contributes to #12713


Internal previews

Toggle expand/collapse
File Preview link
snippets/csharp/System.Collections/ArrayList/Add/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/BinarySearch/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/BinarySearch/source2.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Clear/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/CopyTo/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/CopyTo/source1.cs Preview published page
snippets/csharp/System.Collections/ArrayList/GetEnumerator/program.cs Preview published page
snippets/csharp/System.Collections/ArrayList/IndexOf/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Insert/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/IsFixedSize/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/IsSynchronized/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/IsSynchronized/source2.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Item/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Item/source2.cs Preview published page
snippets/csharp/System.Collections/ArrayList/LastIndexOf/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Overview/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/ReadOnly/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Remove/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Repeat/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Reverse/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Reverse/source1.cs Preview published page
snippets/csharp/System.Collections/ArrayList/SetRange/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Sort/arraylist_sort2.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Sort/arraylist_sort3.cs Preview published page
snippets/csharp/System.Collections/ArrayList/Sort/source.cs Preview published page
snippets/csharp/System.Collections/ArrayList/ToArray/arraylist_toarray.cs Preview published page
snippets/csharp/System.Collections/BitArray/And/source.cs Preview published page
snippets/csharp/System.Collections/BitArray/CopyTo/source.cs Preview published page
snippets/csharp/System.Collections/BitArray/Get/source.cs Preview published page
snippets/csharp/System.Collections/BitArray/Not/source.cs Preview published page

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Modernizes System.Collections C# documentation snippets while preserving their demonstrated behavior.

Changes:

  • Adopts collection expressions, target-typed construction, interpolation, and current formatting.
  • Adds executable entry points for projects containing multiple examples.
  • Renames colliding sample types and methods so snippets compile together.

Reviewed changes

Copilot reviewed 139 out of 139 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
snippets/csharp/System.Collections/Stack/Peek/source.cs Modernizes the Peek example.
snippets/csharp/System.Collections/Stack/Overview/source.cs Modernizes the Stack overview.
snippets/csharp/System.Collections/Stack/IsSynchronized/source2.cs Converts the secondary entry point to Run.
snippets/csharp/System.Collections/Stack/IsSynchronized/source.cs Modernizes synchronization output.
snippets/csharp/System.Collections/Stack/IsSynchronized/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/Stack/IsSynchronized/Program.cs Runs both Stack examples.
snippets/csharp/System.Collections/Stack/CopyTo/source.cs Modernizes the CopyTo example.
snippets/csharp/System.Collections/Stack/Clear/source.cs Modernizes the Clear example.
snippets/csharp/System.Collections/SortedList/SetByIndex/source.cs Modernizes initialization and output.
snippets/csharp/System.Collections/SortedList/Remove/source.cs Modernizes the Remove example.
snippets/csharp/System.Collections/SortedList/Overview/source.cs Modernizes the overview example.
snippets/csharp/System.Collections/SortedList/Overview/remarks.cs Modernizes remarks initialization.
snippets/csharp/System.Collections/SortedList/Overview/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/SortedList/Overview/Program.cs Runs both overview examples.
snippets/csharp/System.Collections/SortedList/IsSynchronized/source2.cs Converts the secondary entry point to Run.
snippets/csharp/System.Collections/SortedList/IsSynchronized/source.cs Modernizes synchronization output.
snippets/csharp/System.Collections/SortedList/IsSynchronized/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/SortedList/IsSynchronized/Program.cs Runs both synchronization examples.
snippets/csharp/System.Collections/SortedList/IndexOfKey/source.cs Modernizes initialization and output.
snippets/csharp/System.Collections/SortedList/GetByIndex/source.cs Modernizes indexed access output.
snippets/csharp/System.Collections/SortedList/CopyTo/source.cs Modernizes the CopyTo example.
snippets/csharp/System.Collections/SortedList/Contains/source.cs Modernizes containment checks.
snippets/csharp/System.Collections/SortedList/Add/source.cs Modernizes the Add example.
snippets/csharp/System.Collections/SortedList/.ctor/sortedlist_ctorint.cs Renames and modernizes the capacity example.
snippets/csharp/System.Collections/SortedList/.ctor/sortedlist_ctordictionary.cs Renames and modernizes the dictionary example.
snippets/csharp/System.Collections/SortedList/.ctor/sortedlist_ctor.cs Renames and modernizes the default example.
snippets/csharp/System.Collections/SortedList/.ctor/Project.csproj Adds an executable .NET 10 project.
snippets/csharp/System.Collections/SortedList/.ctor/Program.cs Runs all constructor examples.
snippets/csharp/System.Collections/ReadOnlyCollectionBase/Overview/source2.cs Renames and modernizes the synchronization example.
snippets/csharp/System.Collections/ReadOnlyCollectionBase/Overview/readonlycollectionbase.cs Modernizes the collection implementation.
snippets/csharp/System.Collections/ReadOnlyCollectionBase/Overview/Project.csproj Adds an executable .NET 10 project.
snippets/csharp/System.Collections/ReadOnlyCollectionBase/Overview/Program.cs Runs both collection examples.
snippets/csharp/System.Collections/Queue/Overview/source.cs Modernizes the Queue overview.
snippets/csharp/System.Collections/Queue/IsSynchronized/source2.cs Converts the secondary entry point to Run.
snippets/csharp/System.Collections/Queue/IsSynchronized/source.cs Modernizes synchronization output.
snippets/csharp/System.Collections/Queue/IsSynchronized/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/Queue/IsSynchronized/Program.cs Runs both Queue examples.
snippets/csharp/System.Collections/Queue/Dequeue/source.cs Modernizes the Dequeue example.
snippets/csharp/System.Collections/Queue/CopyTo/source.cs Modernizes the CopyTo example.
snippets/csharp/System.Collections/Queue/Clear/source.cs Modernizes the Clear example.
snippets/csharp/System.Collections/IStructuralEquatable/Overview/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/IStructuralEquatable/Overview/nanexample1.cs Modernizes formatting and declarations.
snippets/csharp/System.Collections/IList/Overview/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/IEnumerable/Overview/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/IEnumerable/Overview/ienumerator.cs Converts the example to top-level statements.
snippets/csharp/System.Collections/IComparer/reverse.cs Modernizes the reverse comparer.
snippets/csharp/System.Collections/ICollection/IsSynchronized/remarks.cs Modernizes construction and locking syntax.
snippets/csharp/System.Collections/ICollection/IsSynchronized/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/Hashtable/Remove/source.cs Modernizes the Remove example.
snippets/csharp/System.Collections/Hashtable/Overview/remarks.cs Modernizes remarks initialization.
snippets/csharp/System.Collections/Hashtable/Overview/Project.csproj Makes the project executable.
snippets/csharp/System.Collections/Hashtable/Overview/Program.cs Runs both overview examples.
snippets/csharp/System.Collections/Hashtable/Overview/hashtable_example.cs Modernizes the main overview example.
snippets/csharp/System.Collections/Hashtable/IsSynchronized/source.cs Modernizes synchronized Hashtable setup.
snippets/csharp/System.Collections/Hashtable/IsSynchronized/remarks.cs Converts the remarks entry point to Run.
snippets/csharp/System.Collections/Hashtable/IsSynchronized/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/Hashtable/IsSynchronized/Program.cs Runs both synchronization examples.
snippets/csharp/System.Collections/Hashtable/GetEnumerator/source2.cs Modernizes enumeration and output.
snippets/csharp/System.Collections/Hashtable/CopyTo/source.cs Modernizes the CopyTo example.
snippets/csharp/System.Collections/Hashtable/Contains/source.cs Modernizes containment checks.
snippets/csharp/System.Collections/Hashtable/Clear/source.cs Modernizes the Clear example.
snippets/csharp/System.Collections/Hashtable/Add/source.cs Modernizes the Add example.
snippets/csharp/System.Collections/Hashtable/.ctor/Project.csproj Adds an executable .NET 10 project.
snippets/csharp/System.Collections/Hashtable/.ctor/Program.cs Runs all constructor examples.
snippets/csharp/System.Collections/Hashtable/.ctor/hashtable_ctorintfloat.cs Renames and modernizes the capacity/load-factor example.
snippets/csharp/System.Collections/Hashtable/.ctor/hashtable_ctorint.cs Renames and modernizes the capacity example.
snippets/csharp/System.Collections/Hashtable/.ctor/hashtable_ctordictionaryfloat.cs Renames and modernizes the dictionary/load-factor example.
snippets/csharp/System.Collections/Hashtable/.ctor/hashtable_ctordictionary.cs Renames and modernizes the dictionary example.
snippets/csharp/System.Collections/Hashtable/.ctor/hashtable_ctor.cs Renames and modernizes the default example.
snippets/csharp/System.Collections/DictionaryEntry/Overview/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/DictionaryEntry/Overview/DictionaryEntrySample.cs Modernizes initialization and output.
snippets/csharp/System.Collections/DictionaryEntry/Key/remarks.cs Renames the sample dictionary type.
snippets/csharp/System.Collections/DictionaryEntry/Key/Project.csproj Adds an executable .NET 10 project.
snippets/csharp/System.Collections/DictionaryEntry/Key/Program.cs Runs both key examples.
snippets/csharp/System.Collections/DictionaryBase/Overview/Project.csproj Adds an executable .NET 10 project.
snippets/csharp/System.Collections/DictionaryBase/Overview/Program.cs Runs both DictionaryBase examples.
snippets/csharp/System.Collections/Comparer/Overview/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/Comparer/Overview/comparercultures.cs Modernizes culture comparison output.
snippets/csharp/System.Collections/CollectionBase/Overview/remarks.cs Renames and modernizes the synchronization example.
snippets/csharp/System.Collections/CollectionBase/Overview/Project.csproj Adds an executable .NET 10 project.
snippets/csharp/System.Collections/CollectionBase/Overview/Program.cs Runs both CollectionBase examples.
snippets/csharp/System.Collections/CaseInsensitiveComparer/Overview/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/CaseInsensitiveComparer/Overview/caseinsensitive.cs Modernizes Hashtable initialization.
snippets/csharp/System.Collections/BitArray/Xor/source.cs Modernizes the XOR example.
snippets/csharp/System.Collections/BitArray/Overview/source2.cs Converts the locking example to Run.
snippets/csharp/System.Collections/BitArray/Overview/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/BitArray/Overview/Program.cs Runs both BitArray examples.
snippets/csharp/System.Collections/BitArray/Or/source.cs Modernizes the OR example.
snippets/csharp/System.Collections/BitArray/Not/source.cs Modernizes the NOT example.
snippets/csharp/System.Collections/BitArray/Get/source.cs Modernizes the Get example.
snippets/csharp/System.Collections/BitArray/And/source.cs Modernizes the AND example.
snippets/csharp/System.Collections/ArrayList/ToArray/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/ArrayList/ToArray/arraylist_toarray.cs Modernizes initialization and output.
snippets/csharp/System.Collections/ArrayList/Sort/source.cs Modernizes the default sorting example.
snippets/csharp/System.Collections/ArrayList/Sort/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/ArrayList/Sort/Program.cs Runs all sorting examples.
snippets/csharp/System.Collections/ArrayList/Sort/arraylist_sort3.cs Renames and modernizes the range comparer.
snippets/csharp/System.Collections/ArrayList/Sort/arraylist_sort2.cs Renames and modernizes the comparer.
snippets/csharp/System.Collections/ArrayList/SetRange/source.cs Modernizes the SetRange example.
snippets/csharp/System.Collections/ArrayList/Reverse/source1.cs Modernizes range reversal.
snippets/csharp/System.Collections/ArrayList/Reverse/source.cs Modernizes full-list reversal.
snippets/csharp/System.Collections/ArrayList/Reverse/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/ArrayList/Reverse/Program.cs Runs both reversal examples.
snippets/csharp/System.Collections/ArrayList/Repeat/source.cs Modernizes the Repeat example.
snippets/csharp/System.Collections/ArrayList/Remove/source.cs Modernizes the Remove example.
snippets/csharp/System.Collections/ArrayList/ReadOnly/source.cs Modernizes the read-only wrapper example.
snippets/csharp/System.Collections/ArrayList/Overview/source.cs Modernizes the ArrayList overview.
snippets/csharp/System.Collections/ArrayList/LastIndexOf/source.cs Modernizes reverse-search output.
snippets/csharp/System.Collections/ArrayList/Item/source2.cs Modernizes the scrambling example.
snippets/csharp/System.Collections/ArrayList/Item/source.cs Modernizes indexer usage and handling.
snippets/csharp/System.Collections/ArrayList/Item/Project.csproj Makes the project executable.
snippets/csharp/System.Collections/ArrayList/Item/Program.cs Runs both indexer examples.
snippets/csharp/System.Collections/ArrayList/IsSynchronized/source2.cs Converts the locking example to Run.
snippets/csharp/System.Collections/ArrayList/IsSynchronized/source.cs Modernizes synchronization output.
snippets/csharp/System.Collections/ArrayList/IsSynchronized/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/ArrayList/IsSynchronized/Program.cs Runs both synchronization examples.
snippets/csharp/System.Collections/ArrayList/IndexOf/source.cs Modernizes forward-search output.
snippets/csharp/System.Collections/ArrayList/GetEnumerator/Project.csproj Makes the snippet executable.
snippets/csharp/System.Collections/ArrayList/GetEnumerator/program.cs Converts enumeration to top-level code.
snippets/csharp/System.Collections/ArrayList/CopyTo/source1.cs Modernizes the secondary CopyTo example.
snippets/csharp/System.Collections/ArrayList/CopyTo/source.cs Modernizes the primary CopyTo example.
snippets/csharp/System.Collections/ArrayList/CopyTo/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/ArrayList/CopyTo/Program.cs Runs both CopyTo examples.
snippets/csharp/System.Collections/ArrayList/Clear/source.cs Modernizes clearing and capacity output.
snippets/csharp/System.Collections/ArrayList/BinarySearch/source2.cs Modernizes the custom search example.
snippets/csharp/System.Collections/ArrayList/BinarySearch/source.cs Modernizes the standard search example.
snippets/csharp/System.Collections/ArrayList/BinarySearch/Project.csproj Uses the new shared entry point.
snippets/csharp/System.Collections/ArrayList/BinarySearch/Program.cs Runs both search examples.
snippets/csharp/System.Collections/ArrayList/Add/source.cs Modernizes Add and AddRange usage.
Suppressed comments (2)

snippets/csharp/System.Collections/Hashtable/Clear/source.cs:40

  • This ordinary string prints {de.Key} and {de.Value} literally for every entry rather than displaying the Hashtable contents. Prefix it with $ to interpolate both values.
    snippets/csharp/System.Collections/ArrayList/Repeat/source.cs:20
  • Change “initialize” to “initializes” so it is grammatically parallel with “Creates.”
        // Creates a new ArrayList with seven elements and initialize each element with the string "abc".

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread snippets/csharp/System.Collections/ReadOnlyCollectionBase/Overview/source2.cs Outdated
Comment thread snippets/csharp/System.Collections/Hashtable/Clear/source.cs Outdated
Comment thread snippets/csharp/System.Collections/ArrayList/IsSynchronized/source.cs Outdated
Comment thread snippets/csharp/System.Collections/ArrayList/Repeat/source.cs Outdated
Comment thread snippets/csharp/System.Collections/ArrayList/Repeat/source.cs Outdated
Comment thread snippets/csharp/System.Collections/Hashtable/Clear/source.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
@gewarren
gewarren marked this pull request as ready for review August 18, 2026 22:48
@gewarren
gewarren requested a review from a team as a code owner August 18, 2026 22:48

@BillWagner BillWagner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also looks great. One optional suggestion.

And, one forward looking note: We'll probably want to revisit this next year because the next version of C# should include dictionary expressions.

Comment thread snippets/csharp/System.Collections/Hashtable/Contains/source.cs Outdated
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
@gewarren
gewarren enabled auto-merge (squash) August 19, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants