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
Copy file name to clipboardExpand all lines: docs/csharp/whats-new/csharp-14.md
+33-2Lines changed: 33 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,38 @@ You can find any breaking changes introduced in C# 14 in our article on [breakin
28
28
29
29
## Extension members
30
30
31
-
You can learn more details by reading the [feature specification](~/_csharplang/proposals/extensions.md) for the new extension members feature.
31
+
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:
32
+
33
+
```csharp
34
+
publicstaticclassEnumerable
35
+
{
36
+
// Extension block
37
+
extension<TSource>(IEnumerable<TSource> source) // extension members for IEnumerable<TSource>
The members in the first extension block are called as though they're instance members of `IEnumerable<TSource>`, for example `sequence.IsEmpty`. The members in the second extension block are called as though they're static members of `IEnumerable<TSource>`, for example `IEnumerable<int>.Identity`.
61
+
62
+
You can learn more details by reading the article on [extension members](../programming-guide/classes-and-structs/extension-methods.md) in the programming guide, the language reference article on the [`extension` keyword](../language-reference/keywords/extension.md), and the [feature specification](~/_csharplang/proposals/extensions.md) for the new extension members feature.
32
63
33
64
## The `field` keyword
34
65
@@ -124,7 +155,7 @@ You can simplify the preceding code using the `?.` operator:
124
155
customer?.Order=GetCurrentOrder();
125
156
```
126
157
127
-
The right side of the `=` operator is evaluated only when the left side is not null. If `customer` is null, the code doesn't call `GetCurrentOrder`.
158
+
The right side of the `=` operator is evaluated only when the left side isn't null. If `customer` is null, the code doesn't call `GetCurrentOrder`.
128
159
129
160
In addition to assignment, you can use null conditional member access operators with compound assignment operators (`+=`, `-=`, and others). However, increment and decrement, `++` and `--`, aren't allowed.
0 commit comments