-
Notifications
You must be signed in to change notification settings - Fork 6k
Add reference and fundamentals for user defined compound assignment operators #46674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add the speclet to the docset. Add text in What's new in .NET 10 and What's new in C# 14.
7a2907b
to
c8673f1
Compare
This commit updates the files for operators where compound assignment can be overloaded.
docs/csharp/language-reference/operators/operator-overloading.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments for reviewers.
docs/csharp/language-reference/operators/operator-overloading.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 adds support and documentation for user-defined compound assignment, increment, and decrement operators in C# 14 across spec, language reference, and “What’s new” articles. Key changes include:
- Inclusion of a new speclet link and TOC entry for user-defined compound assignment.
- Updates to operator reference topics to describe explicit overloading rules for compound assignment,
++
, and--
. - Addition of code snippets showing instance-based and
void
-returning compound operator implementations.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
docs/csharp/whats-new/csharp-14.md | Added “User defined compound assignment” section |
docs/csharp/specification/toc.yml | Inserted TOC entry for user-defined compound assignment |
docs/csharp/programming-guide/classes-and-structs/members.md | Modified operator member description |
docs/csharp/programming-guide/classes-and-structs/access-modifiers.md | Updated access rules for user-defined operators |
docs/csharp/language-reference/operators/subtraction-operator.md | Refreshed dates and overloadability text |
docs/csharp/language-reference/operators/snippets/shared/OperatorOverloading.cs | Expanded struct with new compound/increment operators |
docs/csharp/language-reference/operators/operator-overloading.md | Added compound assignment overload rules |
docs/csharp/language-reference/operators/boolean-logical-operators.md | Updated code tags and overloadability text |
docs/csharp/language-reference/operators/bitwise-and-shift-operators.md | Refreshed dates, wording, overloadability text |
docs/csharp/language-reference/operators/assignment-operator.md | Refreshed dates and compound assignment note |
docs/csharp/language-reference/operators/arithmetic-operators.md | Refreshed dates, wording, overloadability text |
docs/csharp/language-reference/operators/addition-operator.md | Refreshed dates, wording, overloadability text |
docs/core/whats-new/dotnet-10/overview.md | Added bullets for compound, increment, decrement support |
docfx.json | Registered the new proposal in build configuration |
Comments suppressed due to low confidence (4)
docs/csharp/language-reference/operators/snippets/shared/OperatorOverloading.cs:38
- Using
operand.numerator++
returns the original value and mutates only the local copy. Replace withoperand.numerator + 1
to produce the correctly incremented numerator.
public static Fraction operator ++(Fraction operand) => new Fraction(operand.numerator++, operand.denominator);
docs/csharp/language-reference/operators/snippets/shared/OperatorOverloading.cs:41
- Using
operand.numerator--
returns the original value and mutates only the local copy. Replace withoperand.numerator - 1
to produce the correctly decremented numerator.
public static Fraction operator --(Fraction operand) => new Fraction(operand.numerator--, operand.denominator);
docs/csharp/programming-guide/classes-and-structs/members.md:23
- Regular operator overloads must include the static modifier. Restore the wording to 'public static method' to match actual C# requirements.
|[Operators](../../language-reference/operators/index.md)|Overloaded operators are considered type members. When you overload an operator, you define it as a public method in a type. For more information, see [Operator overloading](../../language-reference/operators/operator-overloading.md).|
docs/csharp/programming-guide/classes-and-structs/access-modifiers.md:68
- The rule should require both
public
andstatic
for regular operators. Update the line to reflect that user-defined operators must bepublic static
.
User-defined operators must always be declared as `public`. For more information, see [Operator overloading](../../language-reference/operators/operator-overloading.md).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
docs/csharp/language-reference/operators/arithmetic-operators.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/operators/arithmetic-operators.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/operators/assignment-operator.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/operators/boolean-logical-operators.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/operators/operator-overloading.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/operators/operator-overloading.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/operators/operator-overloading.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/operators/subtraction-operator.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Fixes #46100
Internal previews
Toggle expand/collapse
+
and+=