Skip to content

Commit 125f65d

Browse files
jamesmontemagnoBillWagnerjongallowayCopilot
authored
Update csharp for preview 7 (#9996)
* Update csharp for preview 7 * Add C# preview 7 features. Add the remaining C# 14 features delivered in .NET 10 preview 7. * Update release-notes/10.0/preview/preview7/csharp.md Co-authored-by: Copilot <[email protected]> * Update release-notes/10.0/preview/preview7/csharp.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Bill Wagner <[email protected]> Co-authored-by: Jon Galloway <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent fc9a6be commit 125f65d

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

release-notes/10.0/preview/preview7/csharp.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,43 @@
22

33
Here's a summary of what's new in C# in this preview release:
44

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.
69

710
C# updates in .NET 10:
811

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.
1041

11-
## Feature
42+
## Named and optional parameters in expression trees
1243

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

Comments
 (0)