Skip to content

Add Expressions: operators article (issue #55334) - #55469

Draft
BillWagner wants to merge 6 commits into
dotnet:mainfrom
BillWagner:expressions-math
Draft

Add Expressions: operators article (issue #55334)#55469
BillWagner wants to merge 6 commits into
dotnet:mainfrom
BillWagner:expressions-math

Conversation

@BillWagner

@BillWagner BillWagner commented Aug 18, 2026

Copy link
Copy Markdown
Member

Create docs/csharp/fundamentals/expressions/operators.md covering arithmetic, unary, increment/decrement, relational, equality survey, conditional-logical, conditional (?:), simple and compound assignment.

  • Add operators snippets project (net10.0, nullable, implicit usings) with 9 region-marked examples; 0 warnings, 0 errors
  • Add operators.md TOC node under Expressions and statements
  • Add reciprocal link in expressions/index.md
  • Add reciprocal link in expressions/equality.md
  • Link excluded operators (shift/bitwise, checked/unchecked) to existing Language Reference pages

Fixes #55334


Internal previews

Toggle expand/collapse
File Preview link
.openpublishing.redirection.csharp.json Preview published page
docs/csharp/fundamentals/expressions/equality.md Preview published page
docs/csharp/fundamentals/expressions/index.md Preview published page
docs/csharp/fundamentals/expressions/operators.md Preview published page
docs/csharp/fundamentals/expressions/snippets/equality/Program.cs Preview published page
docs/csharp/fundamentals/expressions/snippets/operators/Program.cs Preview published page
docs/csharp/fundamentals/object-oriented/objects.md Preview published page
docs/csharp/how-to/index.md Preview published page
docs/csharp/language-reference/compiler-messages/overloaded-operator-errors.md Preview published page
docs/csharp/language-reference/compiler-messages/record-declaration-errors.md Preview published page
docs/csharp/language-reference/operators/equality-operators.md Preview published page
docs/csharp/toc.yml Preview published page

Create docs/csharp/fundamentals/expressions/operators.md covering
arithmetic, unary, increment/decrement, relational, equality survey,
conditional-logical, conditional (?:), simple and compound assignment.

- Add operators snippets project (net10.0, nullable, implicit usings)
  with 9 region-marked examples; 0 warnings, 0 errors
- Add operators.md TOC node under Expressions and statements
- Add reciprocal link in expressions/index.md
- Add reciprocal link in expressions/equality.md
- Link excluded operators (shift/bitwise, checked/unchecked) to
  existing Language Reference pages

Closes dotnet#55334

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5acfb15-adff-4860-a307-213196efda1c
Copilot AI lite review requested due to automatic review settings August 18, 2026 15:35
@dotnetrepoman dotnetrepoman Bot added this to the August 2026 milestone Aug 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new C# Fundamentals article that explains everyday operators (arithmetic, unary, increment/decrement, relational, equality, conditional-logical, conditional ?:, and assignment), along with runnable snippets and navigation updates so the content is discoverable from the Expressions section.

Changes:

  • Adds operators.md under Fundamentals → Expressions and links it from related Expressions articles.
  • Introduces a new snippets project (snippets/operators) with region-tagged examples used by the article.
  • Updates the C# TOC to include the new Operators article.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/csharp/toc.yml Adds the Operators node under Fundamentals → Expressions.
docs/csharp/fundamentals/expressions/operators.md New operators concept article with :::code inclusions and links to reference pages for excluded operator sets.
docs/csharp/fundamentals/expressions/snippets/operators/operators.csproj New .NET snippet project configuration for the operators examples.
docs/csharp/fundamentals/expressions/snippets/operators/Program.cs New runnable sample code containing the operator examples referenced by the article.
docs/csharp/fundamentals/expressions/index.md Adds a cross-link to the new operators article.
docs/csharp/fundamentals/expressions/equality.md Adds a cross-link to the new operators article.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/csharp/fundamentals/expressions/snippets/operators/Program.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@BillWagner BillWagner closed this Aug 18, 2026
@BillWagner BillWagner reopened this Aug 18, 2026
BillWagner and others added 4 commits August 18, 2026 14:11
- Add negative integer division example (-7/2 = -3) to clarify truncation toward zero
- Add negative-operand remainder examples (-7%3 = -1, 7%-3 = 1) with sign rule explanation
- Explain char relational comparison uses Unicode code point values (tied to grade example)
- Update != comment to explicitly say 'true when values are not equal'
- Remove invalid commented-out code from EqualityOps snippet; move === example to NOTE callout in article prose as fenced code block
- Remove nested conditional example and related prose from ConditionalOp section
- Add Console.WriteLine after each compound assignment step (hp progression: 100 -> 120 -> 110 -> 220 -> 73 -> 3)
- Rename 'Operators not covered here' to 'Other C# operators'; expand bullets with concise definitions
- Add displayName to toc.yml entry for operators.md with all covered operators

Copilot-Session: f5acfb15-adff-4860-a307-213196efda1c
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
…otnet#55334)

Retire the three Programming Guide equality articles and preserve their
unique content in docs/csharp/fundamentals/expressions/equality.md:

- equality-comparisons.md
- how-to-test-for-reference-equality-identity.md
- how-to-define-value-equality-for-a-type.md

Content migrated into equality.md:
- Equivalence contract (5 rules: reflexive, symmetric, transitive,
  consistent, null behavior) added to the manual-implementation section.
- New section: 'Records with reference-type members' — explains that
  synthesized record equality uses each member's own equality semantics,
  so List<T>/array members compare by reference; shows custom IEquatable
  override with SequenceEqual as the recommended fix.
- New section: 'Polymorphic equality in unsealed class hierarchies' —
  explains the compile-time dispatch hazard with IEquatable<T>, the
  GetType() guard and virtual Equals pattern for correct unsealed-class
  equality, and notes that sealed classes and records avoid the problem.

Snippet additions to snippets/equality/Program.cs:
- RecordWithCollectionProblem / RecordWithCollectionFixed regions
- PlaylistFixedDefinition type (custom IEquatable record)
- PolymorphicEqualityDefinition (Shape/Circle hierarchy with GetType() guard)
- PolymorphicEqualityUsage region

Intentionally omitted: string-interning note (per Bill's explicit decision).

Retirement wiring:
- 3 redirects added to .openpublishing.redirection.csharp.json
- TOC entries and empty parent node removed from toc.yml
- All 5 inbound links updated: objects.md, how-to/index.md,
  overloaded-operator-errors.md, record-declaration-errors.md,
  equality-operators.md
- Orphaned snippet projects deleted

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5acfb15-adff-4860-a307-213196efda1c
Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Everyday C#: Arithmetic, comparison, logical, conditional, and assignment operators

2 participants