Skip to content

Add C# 15 extension indexers to extension members tutorial - #54802

Merged
BillWagner merged 3 commits into
dotnet:mainfrom
BillWagner:update-extension-tutorial
Jul 16, 2026
Merged

Add C# 15 extension indexers to extension members tutorial#54802
BillWagner merged 3 commits into
dotnet:mainfrom
BillWagner:update-extension-tutorial

Conversation

@BillWagner

@BillWagner BillWagner commented Jul 15, 2026

Copy link
Copy Markdown
Member

Fixes #54658

Updates the extension members tutorial to cover the C# 15 addition of extension indexers.

Changes

  • Reframed the tutorial as "Explore extension members in C# 14 and C# 15" (title, description, intro, checklist).
  • Bumped the sample to .NET 11 preview (net11.0) with <LangVersion>preview</LangVersion>; added a prerequisites note and a project-file step.
  • Added a new "Add extension indexers" section that introduces a Path type storing (dX, dY) offsets, then adds an extension indexer whose:
    • getter computes the absolute Point at an index by summing offsets from Point.Origin (reuses the static extension property and + operator introduced earlier in the tutorial), and
    • setter adjusts only the offset at the requested index so that point lands on the assigned value.
  • New snippet file Path.cs; new PathType, PathIndexer, and PathIndexerUse snippet regions; demo method invoked end to end.

Verification

  • dotnet build and dotnet run succeed on the .NET 11 preview SDK.
  • All :::code id="..."::: references resolve to existing regions.

Draft: opened for early review of approach/wording before final polish.


Internal previews

📄 File 🔗 Preview link
docs/csharp/whats-new/tutorials/extension-members.md Tutorial: Explore extension members in C# 14 and C# 15

Update the extension members tutorial to cover the C# 15 addition of extension indexers. Reframe the tutorial for C# 14 and C# 15, bump the sample to .NET 11 preview with LangVersion preview, and add an "Add extension indexers" section.

The new section introduces a Path type that stores (dX, dY) offsets and adds an extension indexer whose getter computes the absolute Point at an index (from Point.Origin) and whose setter adjusts the offset at that index. Build and run verified on the .NET 11 preview SDK.

Closes dotnet#54658

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7fb88c54-e7d1-47af-b8f2-d60b34e50426
Copilot AI review requested due to automatic review settings July 15, 2026 14:29
@dotnetrepoman dotnetrepoman Bot added this to the July 2026 milestone Jul 15, 2026

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

Updates the existing C# extension members tutorial to also cover the C# 15 preview feature extension indexers, including a new runnable Path example that demonstrates indexed get/set behavior implemented in an extension block.

Changes:

  • Updates the tutorial narrative and checklist to cover both C# 14 extension members and C# 15 extension indexers.
  • Updates the sample project to target net11.0 and use <LangVersion>preview</LangVersion>.
  • Adds a new Path type plus an extension indexer implementation and end-to-end demo output.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/csharp/whats-new/tutorials/snippets/PointExtensions/PointExtensions.csproj Targets net11.0 and enables preview language features needed for extension indexers.
docs/csharp/whats-new/tutorials/snippets/PointExtensions/Path.cs Introduces the Path sample type that stores relative (dX, dY) offsets.
docs/csharp/whats-new/tutorials/snippets/PointExtensions/NewExtensionsMembers.cs Adds a Path extension indexer and reorganizes Point extension blocks for type vs. instance members.
docs/csharp/whats-new/tutorials/snippets/PointExtensions/ExtensionMemberDemonstrations.cs Adds a PathIndexer() demo and updates the scenario numbering accordingly.
docs/csharp/whats-new/tutorials/extension-members.md Expands tutorial content to cover extension indexers, adds prerequisites/project-file step, and links to C# 15 and the speclet.

Proofread the article, update the text description and edit for style.
@BillWagner
BillWagner marked this pull request as ready for review July 15, 2026 16:01
@BillWagner
BillWagner requested a review from a team as a code owner July 15, 2026 16:01
Extend the PathIndexer snippet region to include the private ValidatePathIndex helper the accessors call, so readers see the complete code. Add a sentence noting the shared helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7fb88c54-e7d1-47af-b8f2-d60b34e50426
Comment thread docs/csharp/whats-new/tutorials/extension-members.md
@BillWagner
BillWagner merged commit 7388855 into dotnet:main Jul 16, 2026
9 checks passed
@BillWagner
BillWagner deleted the update-extension-tutorial branch July 17, 2026 20:23
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.

[C# 15-Tutorials]: Extension indexers

3 participants