|
2 | 2 |
|
3 | 3 | Here's a summary of what's new in C# in this preview release:
|
4 | 4 |
|
5 |
| -- [Feature](#feature) |
| 5 | +- [Extension operators](#extension-operators) |
| 6 | +- [Named and optional arguments in expression trees](#named-and-optional-parameters-in-expression-trees) |
| 7 | + |
| 8 | +Preview 7 represents feature complete for C# 14. Any features available only in later previews will be gated behind feature flags. That enables a longer feedback cycle for any additional features. |
6 | 9 |
|
7 | 10 | C# updates in .NET 10:
|
8 | 11 |
|
9 |
| -- [What's new in C# 13](https://learn.microsoft.com/dotnet/csharp/whats-new/csharp-13) documentation |
| 12 | +- [What's new in C# 14](https://learn.microsoft.com/dotnet/csharp/whats-new/csharp-14) documentation |
| 13 | +- [Breaking changes in C# 14](https://learn.microsoft.com/dotnet/csharp/whats-new/breaking-changes/compiler%20breaking%20changes%20-%20dotnet%2010) |
| 14 | + |
| 15 | +## Extension operators |
| 16 | + |
| 17 | +The new extension blocks now include support for *operators*, with the exception of implicit and explicit conversion operators. You can declare operators in extension blocks, as shown in the following example: |
| 18 | + |
| 19 | +```csharp |
| 20 | +public static class Operators |
| 21 | +{ |
| 22 | + extension<TElement>(TElement[] source) where TElement : INumber<TElement> |
| 23 | + { |
| 24 | + public static TElement[] operator *(TElement[] vector, TElement scalar) { ... } |
| 25 | + public static TElement[] operator *(TElement scalar, TElement[] vector) { ... } |
| 26 | + public void operator *=(TElement scalar) { ... } |
| 27 | + public static bool operator ==(TElement[] left, TElement[] right) { ... } |
| 28 | + public static bool operator !=(TElement[] left, TElement[] right) { ... } |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +Several of the rules for extension operators are demonstrated in the preceding example: |
| 34 | + |
| 35 | +- At least one of the operands must be the *extended type*, `TElement[]` in the preceding example. |
| 36 | +- For operators that require pair-wise declarations, such as `==` and `!=` in the preceding example, both operators must be declared in the same static class. They are not required to be in the same `extension` container. |
| 37 | +- Instance compound assignment operators, and instance increment and decrement operators are expected to mutate the current instance. Therefore reference type parameters must be passed by value and value type parameters must be passed by `ref`. These operators can't be declared when the extended type is an unconstrained type parameter. |
| 38 | +- Extension operators, like other extension members, can't use the `abstract`, `virtual`, `override`, or `sealed` modifiers. This is consistent with other extension members. |
| 39 | + |
| 40 | +Extension members are only considered for overload resolution when no applicable predefined or user defined non-extension members are found. |
10 | 41 |
|
11 |
| -## Feature |
| 42 | +## Named and optional parameters in expression trees |
12 | 43 |
|
13 |
| -Something about the feature |
| 44 | +This is a small feature that removes a limitation for *expression trees*. Code in expression trees no longer needs to declare arguments for all optional parameters. In addition, code in expression trees can include named arguments. The call rewriting orders named arguments and provides values for missing optional parameters. Query providers shouldn't need to make any adjustments for this support. |
0 commit comments