You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When no dynamic expressions are involved, C# defaults to static binding, which means that the compile-time types of subexpressions are used in the selection process. However, when one of the subexpressions in the operations listed above is a dynamic expression, the operation is instead dynamically bound.
@@ -160,7 +160,7 @@ The precedence of an operator is established by the definition of its associated
If an operand of a *shift_expression* has the compile-time type `dynamic`, then the expression is dynamically bound ([§12.3.3](expressions.md#1233-dynamic-binding)). In this case, the compile-time type of the expression is `dynamic`, and the resolution described below will take place at run-time using the run-time type of those operands that have the compile-time type `dynamic`.
4512
4513
4513
-
For an operation of the form `x << count` or `x >> count`, binary operator overload resolution ([§12.4.5](expressions.md#1245-binary-operator-overload-resolution)) is applied to select a specific operator implementation. The operands are converted to the parameter types of the selected operator, and the type of the result is the return type of the operator.
4514
+
Dynamic binding uses values of type `enum System.Linq.Expressions.ExpressionType` to communicate binary operator kind to the runtime binder. As there is no enum member specifically representing an unsigned right shift operator, dynamic binding for `>>>` is not supported.
4515
+
4516
+
For an operation of the form `x << count`, `x >> count`, or `X >>> count`, binary operator overload resolution ([§12.4.5](expressions.md#1245-binary-operator-overload-resolution)) is applied to select a specific operator implementation. The left operand is converted to type `T`, where `T` is the first of `int`, `uint`, `long`, and `ulong` that can fully represent all possible values of the operand. The operation is then performed using the precision of type `T`, and the type of the result is `T`.
4514
4517
4515
4518
When declaring an overloaded shift operator, the type of the first operand shall always be the class or struct containing the operator declaration, and the type of the second operand shall always be `int`.
4516
4519
4520
+
The *unsigned_right_shift* operator (`>>>`) shall not be present in an expression tree.
4521
+
4522
+
> *Note*: The semantics of the predefined `>>>` operator on signed types cannot be accurately represented without adding conversions to an unsigned type and back. *end note*
4523
+
4517
4524
The predefined shift operators are listed below.
4518
4525
4519
4526
- Shift left:
@@ -4535,6 +4542,12 @@ The predefined shift operators are listed below.
4535
4542
uintoperator>>(uintx, intcount);
4536
4543
longoperator>>(longx, intcount);
4537
4544
ulongoperator>>(ulongx, intcount);
4545
+
intoperator>>>(intx, intcount);
4546
+
uintoperator>>>(uintx, intcount);
4547
+
nintoperator>>>(nintx, intcount);
4548
+
nuintoperator>>>(nuintx, intcount);
4549
+
longoperator>>>(longx, intcount);
4550
+
ulongoperator>>>(ulongx, intcount);
4538
4551
```
4539
4552
4540
4553
The `>>` operator shifts `x` right by a number of bits computed as described below.
@@ -4543,6 +4556,8 @@ The predefined shift operators are listed below.
4543
4556
4544
4557
When `x` is of type `uint`, `nuint`, or `ulong`, the low-order bits of `x` are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero.
4545
4558
4559
+
The `>>>` operator shifts `x` right by a number of bits computed as follows: The low-order bits of `x` are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero.
4560
+
4546
4561
For the predefined operators, the number of bits to shift is computed as follows:
4547
4562
4548
4563
- When the type of `x` is `int` or `uint`, the shift count is given by the low-order five bits of `count`. In other words, the shift count is computed from `count & 0x1F`. This also applies when the type of `x` is `nint` or `nuint`, and those types have the same size and representation as `int` and `uint`, respectively.
- The `!` null-forgiving operator ([§12.8.9](expressions.md#1289-null-forgiving-expressions)).
7312
7328
-`sizeof` expressions, provided the unmanaged-type is one of the types specified in [§24.6.9](unsafe-code.md#2469-the-sizeof-operator) for which `sizeof` returns a constant value.
0 commit comments