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
Copy file name to clipboardExpand all lines: standard/expressions.md
+26-5Lines changed: 26 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4287,7 +4287,7 @@ Lifted ([§12.4.8](expressions.md#1248-lifted-operators)) forms of the unlifted
4287
4287
4288
4288
For an operation of the form `x + y`, 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.
4289
4289
4290
-
The predefined addition operators are listed below. For numeric and enumeration types, the predefined addition operators compute the sum of the two operands. When one or both operands are of type `string`, the predefined addition operators concatenate the string representation of the operands.
4290
+
The predefined addition operators are listed below. For numeric and enumeration types, the predefined addition operators compute the sum of the two operands. When one or both operands are of type `string`, or both are of type `ReadOnlySpan<byte>`, the predefined addition operators concatenate the string representation of the operands.
4291
4291
4292
4292
- Integer addition:
4293
4293
@@ -4335,15 +4335,15 @@ The predefined addition operators are listed below. For numeric and enumeration
4335
4335
```
4336
4336
4337
4337
At run-time these operators are evaluated exactly as `(E)((U)x + (U)y`).
4338
-
-String concatenation:
4338
+
-UTF-16 string concatenation:
4339
4339
4340
4340
```csharp
4341
4341
stringoperator+(stringx, stringy);
4342
4342
stringoperator+(stringx, objecty);
4343
4343
stringoperator+(objectx, stringy);
4344
4344
```
4345
4345
4346
-
These overloads of the binary `+` operator perform string concatenation. If an operand of string concatenation is `null`, an empty string is substituted. Otherwise, any non-`string` operand is converted to its string representation by invoking the virtual `ToString` method inherited from type `object`. If `ToString` returns `null`, an empty string is substituted.
4346
+
These overloads of the binary `+` operator perform concatenation of UTF-16 strings. If an operand is `null`, an empty UTF-16 string is substituted. Otherwise, any non-`string` operand that is not a ref struct ([§16.2.3](structs.md#1623-ref-modifier)) is converted to its UTF-16 string representation by invoking the virtual `ToString` method inherited from type `object`. If `ToString` returns `null`, an empty UTF-16 string is substituted.
4347
4347
4348
4348
> *Example*:
4349
4349
>
@@ -4372,7 +4372,28 @@ The predefined addition operators are listed below. For numeric and enumeration
4372
4372
>
4373
4373
>*endexample*
4374
4374
4375
-
Theresultofthestringconcatenationoperatorisa `string` thatconsistsofthecharactersoftheleftoperandfollowedbythecharactersoftherightoperand. Thestringconcatenationoperatorneverreturnsa `null` value. A `System.OutOfMemoryException` maybethrownifthereisnotenoughmemoryavailabletoallocatetheresultingstring.
4375
+
Theresultoftheoperatorisa `string` thatconsistsofthecharactersoftheleftoperandfollowedbythecharactersoftherightoperand. Thestringconcatenationoperatorneverreturnsa `null` value. A `System.OutOfMemoryException` maybethrownifthereisnotenoughmemoryavailabletoallocatetheresultingstring.
This overload of the binary `+` operator performs concatenation of UTF-8 string literals and the concatenated results thereof (which is much more restrictive than for UTF-16 string concatenation). The operands shall be UTF-8-encoded values.
4383
+
The result of the operator is a ReadOnlySpan<byte> that consists of the bytes of the left operand followed by the bytes of the right operand. The result may be used directly as an operand to the UTF-8 string concatenation operator.
0 commit comments