Everyday C# - Expressions overview - #55355
Open
BillWagner wants to merge 11 commits into
Open
Conversation
New article: docs/csharp/fundamentals/expressions/index.md - Beginner-friendly overview: what expressions are, value-producing vs void - Operator precedence taught as three memorable tiers (arithmetic, comparison, logical) - No full precedence table; links to language-reference/operators/index.md - Parentheses section with executable snippet - Short-circuit evaluation section with executable snippet - TOC entry added under 'Expressions and statements' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2091fd4c-9f7b-4948-9282-a93f05502675
…vanced details - Replace boolean &/| ParenthesesClarity snippet with &&/|| example that clearly shows parentheses changing the result (isAdmin/isOwner pattern) - Remove non-short-circuit &/| sentence from Short-circuit section - Trim Associativity to left-associative only; drop chained assignment - Replace (x++)+(x++) operand-order example with a clean arithmetic example Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2091fd4c-9f7b-4948-9282-a93f05502675
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new “Expressions overview” entry to the C# fundamentals documentation, introducing expressions, operator precedence, associativity, and short-circuit evaluation, with supporting runnable snippets.
Changes:
- Add a new fundamentals article:
fundamentals/expressions/index.md. - Add a new snippet project and sample code used by the article.
- Wire the new article into the C# TOC under “Expressions and statements”.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docs/csharp/toc.yml | Adds “Expressions overview” to the Expressions and statements section. |
| docs/csharp/fundamentals/expressions/index.md | New conceptual article explaining expressions and precedence, with code includes. |
| docs/csharp/fundamentals/expressions/snippets/expressions/Program.cs | Adds snippet regions demonstrating parentheses and short-circuit behavior. |
| docs/csharp/fundamentals/expressions/snippets/expressions/expressions.csproj | Adds a runnable snippet project for the new examples. |
Suppressed comments (1)
docs/csharp/fundamentals/expressions/index.md:34
- Markdown auto-numbering lets you use
1.for every item in an ordered list. Using2.and3.makes the list harder to edit later because inserting an item requires renumbering.
1. **Arithmetic first** — `*`, `/`, `%` bind tighter than `+` and `-`. Multiplication and division happen before addition and subtraction.
2. **Comparison next** — `<`, `>`, `<=`, `>=`, `==`, `!=` bind less tightly than arithmetic, so arithmetic completes before the comparison.
3. **Logical last** — `&&` and `||` bind least tightly of the common operators, so comparisons complete before the logical combination.
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Remove odd tip sentence 'Prefer standalone statements for clarity' - Intro now uses inline expressions (3 + 4 * 2, total > 10) instead of compilable statement snippets; adds expression-vs-statement comparison - New 'Combining expressions' section explains why precedence matters and notes readers can use parentheses instead of memorizing rules - Rewrites 'Operand evaluation order' around two clear rules: left-to-right evaluation and short-circuit operators; uses paper-and-pencil analogy - Adds StepByStep snippet showing interim-value computation - Expands short-circuit coverage to include ?:, ?., ?[], and ??= - Folds associativity into evaluation section as a small definition rather than a standalone heading - Fixes all review typos (comparision, short circut, Mayble) in polished prose Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b155fe4-7996-4e57-ae91-d560587cc26d
…pencil walkthrough - Fix 'assignment statement' inaccuracy: explain int total = ... as a variable declaration statement whose initializer expression is evaluated and assigned - Add 'primary and unary first' tier to operator-precedence list, covering member access, method calls, indexing, null-conditional access, and unary operators; update tier count references throughout - Add explicit paper-and-pencil walkthrough using 3 + 6 / 2, showing each interim step (6/2 -> 3, then 3+3 -> 6) in both ASCII diagram and snippet Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b155fe4-7996-4e57-ae91-d560587cc26d
The range operator (..) sits in its own precedence band between Unary and Multiplicative in the C# spec table — above arithmetic, not below it. Expand tier 1 to 'Primary, unary, and range', naming all three groups and explaining what range does (slice expressions like array[1..4]). Note that each group has its own band while all three precede arithmetic, which is technically accurate and satisfies the pedagogical request. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b155fe4-7996-4e57-ae91-d560587cc26d
The previous wording said 'prefix/postfix increment (++i)' but ++i is only prefix. Separate them so each label matches its example. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b155fe4-7996-4e57-ae91-d560587cc26d
…nd range' - Restore heading 'Primary, unary, and range' (Bill's chosen wording), superseding the local edit that had changed it to 'Primary and unary' - Add opening paragraph to Operator precedence defining what 'binding' means: how operators claim operands in a combined expression, explicitly kept distinct from runtime operand evaluation order (cross-linked to How expressions are evaluated) - Note that C# has more precedence groups than the four in the summary; the additional groups enforce familiar rules like multiplication before addition - Expand tier 1 to sub-bullets clearly stating that primary, unary, and range are three distinct precedence groups combined here because all bind before arithmetic - Replace full-table sentence with natural 'For the complete hierarchy...' close - Remove stale 'four tiers' wording from Combining expressions intro and from parentheses subsection; transitions now flow without redundant reassurances Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b155fe4-7996-4e57-ae91-d560587cc26d
After the prose walk-through of score + bonus > threshold && attempts < maxAttempts, add the same expression with explicit grouping parentheses: ((score + bonus) > threshold) && (attempts < maxAttempts) This reinforces the precedence explanation before the parentheses subsection without duplicating its distinct content (which uses different variables and focuses on cases where parentheses change the result). Preserves the minor prose tweaks already present as local edits. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b155fe4-7996-4e57-ae91-d560587cc26d
…trast The previous paragraph defined precedence via 'binding order' then immediately disclaimed that binding isn't runtime order — confusing for beginners. Rewrite uses only structural language: - Precedence determines how a combined expression *groups* into sub-expressions - 'Binds more tightly' means the expression is structured as if parenthesized - Concrete example: 3 + 4 * 2 groups as 3 + (4 * 2), not (3 + 4) * 2 No mention of runtime evaluation order in this paragraph. The 'How expressions are evaluated' section owns that concept. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9b155fe4-7996-4e57-ae91-d560587cc26d
BillWagner
marked this pull request as ready for review
August 14, 2026 19:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #55333
Add the basics for expressions, and contrast them with statements.
Internal previews