You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#47268Fixes#47280
Extension indexers didn't make C# 14 (although properties did). Remove those examples.
Add examples and discussion for extension operators, which are available in RC1.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/keywords/extension.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
---
2
2
title: "Extension member declarations"
3
3
description: "Learn the syntax to declare extension members in C#. Extension members enable you to add functionality to types and interfaces in those instances where you don't have the source for the original type. Extensions are often paired with generic interfaces to implement a common set of functionality across all types that implement that interface."
4
-
ms.date: 04/17/2025
4
+
ms.date: 09/17/2025
5
5
f1_keywords:
6
6
- "extension_CSharpKeyword"
7
7
- "extension"
8
8
---
9
9
# Extension declaration (C# Reference)
10
10
11
-
Beginning with C# 14, top level, nongeneric `static class` declarations can use `extension`containers to declare *extension members*. Extension members are methods or properties and can appear to be instance or static members. Earlier versions of C# enable *extension methods* by adding `this` as a modifier to the first parameter of a static method declared in a top-level, nongeneric static class.
11
+
Beginning with C# 14, top level, nongeneric `static class` declarations can use `extension`blocks to declare *extension members*. Extension members are methods or properties and can appear to be instance or static members. Earlier versions of C# enable *extension methods* by adding `this` as a modifier to the first parameter of a static method declared in a top-level, nongeneric static class.
12
12
13
-
The `extension` block specifies the type and receiver for extension members. You can declare methods and properties inside the `extension` declaration. The following example declares a single extension block that defines an instance extension method and an instance property.
13
+
The `extension` block specifies the type and receiver for extension members. You can declare methods, properties or operators inside the `extension` declaration. The following example declares a single extension block that defines an instance extension method, an instance property, and a static operator method.
You can declare any number of members in a single container, as long as they share the same receiver. You can declare as many extension blocks in a single class as well. Different extensions don't need to declare the same type or name of receiver. The extension parameter doesn't need to include the parameter name if the only members are static:
23
+
You can declare any number of members in a single block, as long as they share the same receiver. You can declare as many extension blocks in a single class as well. Different extensions don't need to declare the same type or name of receiver. The extension parameter doesn't need to include the parameter name if the only members are static:
Operators are called as though they are user defined operators on the type.
32
+
31
33
> [!IMPORTANT]
32
34
> An extension doesn't introduce a *scope* for member declarations. All members declared in a single class, even if in multiple extensions, must have unique signatures. The generated signature includes the receiver type in its name for static members and the receiver parameter for extension instance members.
Copy file name to clipboardExpand all lines: docs/csharp/programming-guide/classes-and-structs/extension-methods.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Extension members"
3
3
description: Extension members in C# enable you to add methods, properties, or operators to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.
4
-
ms.date: 04/15/2025
4
+
ms.date: 09/17/2025
5
5
helpviewer_keywords:
6
6
- "methods [C#], adding to existing types"
7
7
- "extension methods [C#]"
@@ -12,7 +12,9 @@ helpviewer_keywords:
12
12
13
13
Extension members enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.
14
14
15
-
Beginning with C# 14, there are two syntaxes you use to define extension methods. C# 14 adds [`extension`](../../language-reference/keywords/extension.md) containers, where you define multiple extension members for a type or an instance of a type. Before C# 14, you add the [`this`](../../language-reference/keywords/this.md) modifier to the first parameter of a static method to indicate that the method appears as a member of an instance of the parameter type.
15
+
Beginning with C# 14, there are two syntaxes you use to define extension methods. C# 14 adds [`extension`](../../language-reference/keywords/extension.md) blocks, where you define multiple extension members for a type or an instance of a type. Before C# 14, you add the [`this`](../../language-reference/keywords/this.md) modifier to the first parameter of a static method to indicate that the method appears as a member of an instance of the parameter type.
16
+
17
+
Extension blocks support multiple member types: methods, properties, and operators. With extension blocks, you can define both instance extensions and static extensions. Instance extensions extend an instance of the type; static extensions extend the type itself. The form of extension methods declared with the `this` modifier supports instance extension methods.
16
18
17
19
Extension methods are static methods, but they're called as if they were instance methods on the extended type. For client code written in C#, F# and Visual Basic, there's no apparent difference between calling an extension method and the methods defined in a type. Both forms of extension methods are compiled to the same IL (Intermediate Language). Consumers of extension members don't need to know which syntax was used to define extension methods.
Copy file name to clipboardExpand all lines: docs/csharp/whats-new/csharp-14.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: What's new in C# 14
3
3
description: Get an overview of the new features in C# 14. C# 14 ships with .NET 10.
4
-
ms.date: 04/17/2025
4
+
ms.date: 09/17/2025
5
5
ms.topic: whats-new
6
6
ms.update-cycle: 180-days
7
7
---
@@ -30,7 +30,7 @@ You can find any breaking changes introduced in C# 14 in our article on [breakin
30
30
31
31
## Extension members
32
32
33
-
C# 14 adds new syntax to define *extension members*. The new syntax enables you to declare *extension properties* in addition to extension methods. You can also declare extension members that extend the type, rather than an instance of the type. In other words, these new extension members can appear as static members of the type you extend. The following code example shows an example of the different kinds of extension members you can declare:
33
+
C# 14 adds new syntax to define *extension members*. The new syntax enables you to declare *extension properties* in addition to extension methods. You can also declare extension members that extend the type, rather than an instance of the type. In other words, these new extension members can appear as static members of the type you extend. These extensions can include user defined operators implemented as static extension methods. The following code example shows an example of the different kinds of extension members you can declare:
0 commit comments