-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Clarify C# 14 requirements and show both extension method syntaxes #51327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
…lets Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
…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>
Done! I've restructured the article to address issue #50803. The article now has two separate sections:
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 |
BillWagner
left a comment
There was a problem hiding this 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
...-extension-method-classic/how-to-implement-and-call-a-custom-extension-method-classic.csproj
Outdated
Show resolved
Hide resolved
…-to-implement-and-call-a-custom-extension-method-classic/how-to-implement-and-call-a-custom-extension-method-classic.csproj
There was a problem hiding this 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> |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
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.
The article uses the new C# 14
extensionblock 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:
extensionblock syntaxthismodifier syntaxCreated new code example for classic syntax:
public static int WordCount(this string str)syntaxUpdated introduction to explain both syntaxes are available
Each section has:
The C# 14 syntax:
The classic syntax (earlier versions):
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