Skip to content
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

Update expressions.md #1076

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/csharp/tour-of-csharp/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ ms.assetid: 20d5eb10-7381-47b9-ad90-f1cc895aa27e

# Expressions

***Expressions*** are constructed from ***operands*** and ***operators***. The operators of an expression indicate which operations to apply to the operands. Examples of operators include `+`, `-`, `*`, `/`, and `new`. Examples of operands include literals, fields, local variables, and expressions.
*Expressions* are constructed from *operands* and *operators*. The operators of an expression indicate which operations to apply to the operands. Examples of operators include `+`, `-`, `*`, `/`, and `new`. Examples of operands include literals, fields, local variables, and expressions.

When an expression contains multiple operators, the ***precedence*** of the operators controls the order in which the individual operators are evaluated. For example, the expression `x + y * z` is evaluated as `x + (y * z)` because the `*` operator has higher precedence than the `+` operator.
When an expression contains multiple operators, the *precedence* of the operators controls the order in which the individual operators are evaluated. For example, the expression `x + y * z` is evaluated as `x + (y * z)` because the `*` operator has higher precedence than the `+` operator.

When an operand occurs between two operators with the same precedence, the ***associativity*** of the operators controls the order in which the operations are performed:
When an operand occurs between two operators with the same precedence, the *associativity* of the operators controls the order in which the operations are performed:

* Except for the assignment operators, all binary operators are ***left-associative***, meaning that operations are performed from left to right. For example, `x + y + z` is evaluated as `(x + y) + z`.
* The assignment operators and the conditional operator (`?:`) are ***right-associative***, meaning that operations are performed from right to left. For example, `x = y = z` is evaluated as `x = (y = z)`.
* Except for the assignment operators, all binary operators are *left-associative*, meaning that operations are performed from left to right. For example, `x + y + z` is evaluated as `(x + y) + z`.
* The assignment operators and the conditional operator (`?:`) are *right-associative*, meaning that operations are performed from right to left. For example, `x = y = z` is evaluated as `x = (y = z)`.

Precedence and associativity can be controlled using parentheses. For example, `x + y * z` first multiplies `y` by `z` and then adds the result to `x`, but `(x + y) * z` first adds `x` and `y` and then multiplies the result by `z`.

Most operators can be ***overloaded***. Operator overloading permits user-defined operator implementations to be specified for operations where one or both of the operands are of a user-defined class or struct type.
Most operators can be *overloaded*. Operator overloading permits user-defined operator implementations to be specified for operations where one or both of the operands are of a user-defined `class` or `struct` type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be overloaded - no capital L

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks to me as a small l..

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting - it looks like a capital L in the output above, but it appears to be rendering as a lowercase l in the built content. Could this be a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it depends on the font used by the browser!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in this case we didn't have to use inline code for class or struct. I can expand our style guide, but basically we use inline code (or `) for things we want to lock for localization. So language keywords are an example, variable names, etc. In here, we're not talking about the keyword class or the keyword struct, but the concept.


The following summarizes C#’s operators, listing the operator categories in order of precedence from highest to lowest. Operators in the same category have equal precedence. Under each category is a list of expressions in that category along with the description of that expression type.

Expand All @@ -39,7 +39,7 @@ The following summarizes C#’s operators, listing the operator categories in or
- `new T(...){...}`: Object creation with initializer
- `new {...}`: Anonymous object initializer
- `new T[...]`: Array creation
- `typeof(T)`: Obtain System.Type object for `T`
- `typeof(T)`: Obtain `System.Type` object for `T`
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: You could also style System.Type as System.Type and that would create a link to the API doc.

- `checked(x)`: Evaluate expression in checked context
- `unchecked(x)`: Evaluate expression in unchecked context
- `default(T)`: Obtain default value of type `T`
Expand Down Expand Up @@ -78,13 +78,13 @@ The following summarizes C#’s operators, listing the operator categories in or
* Logical XOR
- `x ^ y`: Integer bitwise XOR, boolean logical XOR
* Logical OR
`x | y`: Integer bitwise OR, boolean logical OR
- `x | y`: Integer bitwise OR, boolean logical OR
* Conditional AND
- `x && y`: Evaluates `y` only if `x` is not `false`
* Conditional OR
- `x || y`: Evaluates `y` only if `x` is not `true`
* Null coalescing
- `X ?? y`: Evaluates to `y` if `x` is null, to `x` otherwise
- `x ?? y`: Evaluates to `y` if `x` is null, to `x` otherwise
* Conditional
- `x ? y : z`: Evaluates `y` if `x` is `true`, `z` if `x` is `false`
* Assignment or anonymous function
Expand Down