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
@@ -4282,7 +4282,7 @@ Lifted ([§12.4.8](expressions.md#1248-lifted-operators)) forms of the unlifted
4282
4282
4283
4283
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.
4284
4284
4285
-
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.
4285
+
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.
4286
4286
4287
4287
- Integer addition:
4288
4288
@@ -4332,15 +4332,15 @@ The predefined addition operators are listed below. For numeric and enumeration
4332
4332
```
4333
4333
4334
4334
At run-time these operators are evaluated exactly as `(E)((U)x + (U)y`).
4335
-
-String concatenation:
4335
+
-UTF-16 string concatenation:
4336
4336
4337
4337
```csharp
4338
4338
stringoperator+(stringx, stringy);
4339
4339
stringoperator+(stringx, objecty);
4340
4340
stringoperator+(objectx, stringy);
4341
4341
```
4342
4342
4343
-
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.
4343
+
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.
4344
4344
4345
4345
> *Example*:
4346
4346
>
@@ -4369,7 +4369,28 @@ The predefined addition operators are listed below. For numeric and enumeration
4369
4369
>
4370
4370
>*endexample*
4371
4371
4372
-
Theresultofthestringconcatenationoperatorisa `string` thatconsistsofthecharactersoftheleftoperandfollowedbythecharactersoftherightoperand. Thestringconcatenationoperatorneverreturnsa `null` value. A `System.OutOfMemoryException` maybethrownifthereisnotenoughmemoryavailabletoallocatetheresultingstring.
4372
+
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.
4380
+
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