Skip to content

Conversation

BillWagner
Copy link
Member

@BillWagner BillWagner commented Oct 3, 2025

@BillWagner BillWagner marked this pull request as ready for review October 6, 2025 18:48
@BillWagner BillWagner requested a review from a team as a code owner October 6, 2025 18:48
@BillWagner
Copy link
Member Author

Tagging @adegeo because he gave me some ideas for extensions

Copy link
Contributor

@Copilot 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 creates a comprehensive tutorial for C# 14 extension members, a new language feature that enhances the existing extension methods functionality by enabling properties, operators, and type-level extensions.

Key Changes:

  • Added a new tutorial demonstrating extension members syntax and capabilities
  • Created supporting code samples comparing traditional extension methods with new extension member features
  • Updated the table of contents to include the new tutorial

Reviewed Changes

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

File Description
docs/csharp/whats-new/tutorials/extension-members.md Main tutorial document explaining extension members concepts and syntax
docs/csharp/toc.yml Added navigation entry for the new extension members tutorial
docs/csharp/whats-new/tutorials/snippets/PointExtensions/*.cs Code samples demonstrating both traditional extension methods and new extension members

@@ -0,0 +1,190 @@
---
title: Explore extension members in C# 14 to enhance existing types
description: "C# 14 enables provides new syntax for extensions that support properties and operators, and enables extensions on a type as well as an instance. Learn to use them, and how to migrate existing extension methods to extension members"
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

Corrected grammatical error 'enables provides' to 'enables' or 'provides'.

Suggested change
description: "C# 14 enables provides new syntax for extensions that support properties and operators, and enables extensions on a type as well as an instance. Learn to use them, and how to migrate existing extension methods to extension members"
description: "C# 14 provides new syntax for extensions that support properties and operators, and enables extensions on a type as well as an instance. Learn to use them, and how to migrate existing extension methods to extension members"

Copilot uses AI. Check for mistakes.

ms.topic: tutorial
ms.date: 10/06/2025
ai-usage: ai-assisted
#customer intent: As a C# developer, I reduce repeated code by introducting extension members for common tasks
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'introducting' to 'introducing'.

Suggested change
#customer intent: As a C# developer, I reduce repeated code by introducting extension members for common tasks
#customer intent: As a C# developer, I reduce repeated code by introducing extension members for common tasks

Copilot uses AI. Check for mistakes.

cd PointExtensions
```

1. Copy the following code into a new filed named `ExtensionMethods.cs`:
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'filed' to 'file'.

Suggested change
1. Copy the following code into a new filed named `ExtensionMethods.cs`:
1. Copy the following code into a new file named `ExtensionMethods.cs`:

Copilot uses AI. Check for mistakes.

Comment on lines +47 to +49
public void Rotate(int angleInDegress)
{
double theta = ((double)angleInDegress * Math.PI) / 180.0;
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'angleInDegress' to 'angleInDegrees'.

Suggested change
public void Rotate(int angleInDegress)
{
double theta = ((double)angleInDegress * Math.PI) / 180.0;
public void Rotate(int angleInDegrees)
{
double theta = ((double)angleInDegrees * Math.PI) / 180.0;

Copilot uses AI. Check for mistakes.

Comment on lines +23 to +25
public static void Rotate(this Point point, int angleInDegress)
{
double theta = ((double)angleInDegress * Math.PI) / 180.0;
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'angleInDegress' to 'angleInDegrees'.

Suggested change
public static void Rotate(this Point point, int angleInDegress)
{
double theta = ((double)angleInDegress * Math.PI) / 180.0;
public static void Rotate(this Point point, int angleInDegrees)
{
double theta = ((double)angleInDegrees * Math.PI) / 180.0;

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@meaghanlewis meaghanlewis left a comment

Choose a reason for hiding this comment

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

Great tutorial @BillWagner! I left primarily style changes for you to consider.


The extension operators make point arithmetic as natural as working with built-in numeric types.

## Add More operators
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
## Add More operators
## Add more operators


## Migrate instance methods to extension members

Extension members also support instance methods. You don't have to change existing extension methods. The old and new forms are binary and source compatible. If you want to keep all your extensions in one container, you can. Migrate traditional extension methods to the new syntax maintains the same functionality.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Extension members also support instance methods. You don't have to change existing extension methods. The old and new forms are binary and source compatible. If you want to keep all your extensions in one container, you can. Migrate traditional extension methods to the new syntax maintains the same functionality.
Extension members also support instance methods. You don't have to change existing extension methods. The old and new forms are binary and source compatible. If you want to keep all your extensions in one container, you can. Migrating traditional extension methods to the new syntax maintains the same functionality.


## Related content

* [Extension methods (C# Programming Guide)](/dotnet/csharp/programming-guide/classes-and-structs/extension-methods)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* [Extension methods (C# Programming Guide)](/dotnet/csharp/programming-guide/classes-and-structs/extension-methods)
- [Extension methods (C# Programming Guide)](/dotnet/csharp/programming-guide/classes-and-structs/extension-methods)

## Related content

* [Extension methods (C# Programming Guide)](/dotnet/csharp/programming-guide/classes-and-structs/extension-methods)
* [What's new in C# 14](/dotnet/csharp/whats-new/csharp-14)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* [What's new in C# 14](/dotnet/csharp/whats-new/csharp-14)
- [What's new in C# 14](/dotnet/csharp/whats-new/csharp-14)


* [Extension methods (C# Programming Guide)](/dotnet/csharp/programming-guide/classes-and-structs/extension-methods)
* [What's new in C# 14](/dotnet/csharp/whats-new/csharp-14)
* [Operator overloading (C# reference)](/dotnet/csharp/language-reference/operators/operator-overloading)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* [Operator overloading (C# reference)](/dotnet/csharp/language-reference/operators/operator-overloading)
- [Operator overloading (C# reference)](/dotnet/csharp/language-reference/operators/operator-overloading)

Point rotatePoint2 = new Point(5, 5);
Console.WriteLine($"Before Rotate: {rotatePoint2}");
rotatePoint2.Rotate(45);
Console.WriteLine($"After Rotate(45�): {rotatePoint2}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Console.WriteLine($"After Rotate(45): {rotatePoint2}");
Console.WriteLine($"After Rotate(45°): {rotatePoint2}");

Point rotatePoint3 = new Point(3, 4);
Console.WriteLine($"Before Rotate: {rotatePoint3}");
rotatePoint3.Rotate(180);
Console.WriteLine($"After Rotate(180�): {rotatePoint3}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Console.WriteLine($"After Rotate(180): {rotatePoint3}");
Console.WriteLine($"After Rotate(180°): {rotatePoint3}");

Point rotatePoint1 = new Point(10, 0);
Console.WriteLine($"Before Rotate: {rotatePoint1}");
rotatePoint1.Rotate(90);
Console.WriteLine($"After Rotate(90�): {rotatePoint1}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Console.WriteLine($"After Rotate(90): {rotatePoint1}");
Console.WriteLine($"After Rotate(90°): {rotatePoint1}");

Point rotatePoint2 = new Point(5, 5);
Console.WriteLine($"Before Rotate: {rotatePoint2}");
rotatePoint2.Rotate(45);
Console.WriteLine($"After Rotate(45�): {rotatePoint2}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Console.WriteLine($"After Rotate(45): {rotatePoint2}");
Console.WriteLine($"After Rotate(45°): {rotatePoint2}");

Point rotatePoint3 = new Point(3, 4);
Console.WriteLine($"Before Rotate: {rotatePoint3}");
rotatePoint3.Rotate(180);
Console.WriteLine($"After Rotate(180�): {rotatePoint3}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Console.WriteLine($"After Rotate(180): {rotatePoint3}");
Console.WriteLine($"After Rotate(180°): {rotatePoint3}");

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.

[C# 14-Tutorials]: New Feature - Extensions
2 participants