Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

The article uses the new C# 14 extension block syntax and targets .NET 10, but didn't state these requirements. Additionally, the text described the classic extension method syntax while the example showed only the C# 14 syntax, causing confusion (issue #50803).

Fixes #50803
Fixes #51326

Changes

  • Restructured article into two sections:

    • "Extension blocks (C# 14 and later)" - Shows the C# 14 extension block syntax
    • "Extension methods (earlier versions)" - Shows the classic this modifier syntax
  • Created new code example for classic syntax:

    • Added complete, compilable example targeting .NET 9
    • Uses public static int WordCount(this string str) syntax
  • Updated introduction to explain both syntaxes are available

  • Each section has:

    • Its own step-by-step instructions
    • Complete code example that matches the text
    • Clear version requirements

The C# 14 syntax:

extension(string str)
{
    public int WordCount() { ... }
}

The classic syntax (earlier versions):

public static int WordCount(this string str) { ... }

This eliminates the inconsistency between the text describing the classic approach and examples showing only the C# 14 syntax.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Internal previews

📄 File 🔗 Preview link
docs/csharp/programming-guide/classes-and-structs/how-to-implement-and-call-a-custom-extension-method.md docs/csharp/programming-guide/classes-and-structs/how-to-implement-and-call-a-custom-extension-method

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
…lets

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copilot AI changed the title [WIP] Clarify that C# 14 is needed for this example Clarify C# 14 and .NET 10 requirements for extension method example Jan 27, 2026
Copilot AI requested a review from BillWagner January 27, 2026 15:12
@BillWagner
Copy link
Member

@copilot Can you update this PR to also fix #50803? It involves the same file, and your current edits are already close.

Copilot AI and others added 2 commits January 27, 2026 20:29
…yntax

- Added separate sections for C# 14 extension blocks and classic syntax
- Created new code example showing classic extension method approach
- Updated introduction to explain both syntaxes are available
- Moved general information to end of article
- Addresses issue #50803

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 27, 2026

@copilot Can you update this PR to also fix #50803? It involves the same file, and your current edits are already close.

Done! I've restructured the article to address issue #50803. The article now has two separate sections:

  1. "Extension blocks (C# 14 and later)" - showing the new C# 14 syntax with the existing example
  2. "Extension methods (earlier versions)" - showing the classic this modifier syntax with a new code example

This eliminates the confusion between the text describing the classic approach and the example using the C# 14 syntax. Both sections have their own step-by-step instructions and complete, compilable examples.

Completed in commit dd9df6c

Copilot AI changed the title Clarify C# 14 and .NET 10 requirements for extension method example Clarify C# 14 requirements and show both extension method syntaxes Jan 27, 2026
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This looks good, once I update the version

…-to-implement-and-call-a-custom-extension-method-classic/how-to-implement-and-call-a-custom-extension-method-classic.csproj
@BillWagner BillWagner marked this pull request as ready for review January 27, 2026 20:33
@BillWagner BillWagner requested a review from a team as a code owner January 27, 2026 20:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the C# extension method how-to article to clearly distinguish between the new C# 14 extension block syntax and the classic this-parameter extension method syntax, and adds a dedicated classic syntax example. It aims to resolve confusion where the text previously described the classic syntax while the example only showed the C# 14 extension block syntax.

Changes:

  • Added a new classic extension-method example project and code snippet, and wired it into the article.
  • Restructured the article into separate sections for C# 14 extension blocks and pre-C# 14 classic extension methods, each with its own step-by-step instructions and matching snippets.
  • Clarified the introduction and general information so version requirements and calling semantics are consistent across text and examples.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
docs/csharp/programming-guide/classes-and-structs/snippets/how-to-implement-and-call-a-custom-extension-method-classic/how-to-implement-and-call-a-custom-extension-method-classic.csproj New project file for the classic extension-method example; targets net10.0 and enables implicit usings and nullable.
docs/csharp/programming-guide/classes-and-structs/snippets/how-to-implement-and-call-a-custom-extension-method-classic/Program.cs New classic extension-method sample using public static int WordCount(this string str) with top-level statements and a CustomExtensions namespace.
docs/csharp/programming-guide/classes-and-structs/how-to-implement-and-call-a-custom-extension-method.md Restructured article into separate sections for extension blocks and classic extension methods; updated narrative, instructions, and snippet references accordingly.


<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The PR description states that the new classic extension-method example targets .NET 9, but this project is configured for net10.0. To avoid confusion, either update the target framework here to net9.0 (if that was the original intent) or adjust the PR description and any related documentation text to match net10.0.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify that C# 14 is needed for this example Text describing extension methods does not match example using extension block

2 participants