-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Closed
Update expressions.md #1076
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
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. | ||
|
||
|
@@ -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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
|
@@ -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 | ||
|
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.
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.
Should be overloaded - no capital L
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.
It looks to me as a small l..
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.
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?
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.
Maybe it depends on the font used by the browser!
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.
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.