From 4dedd0cb19420611aa54cc5bce65f881c8b0f42a Mon Sep 17 00:00:00 2001 From: pkulikov Date: Wed, 22 Apr 2020 20:17:55 +0200 Subject: [PATCH] String concatenation: clarify behavior for null --- docs/csharp/language-reference/operators/addition-operator.md | 4 ++-- .../language-reference/operators/snippets/AdditionOperator.cs | 2 ++ docs/csharp/language-reference/operators/snippets/Program.cs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/csharp/language-reference/operators/addition-operator.md b/docs/csharp/language-reference/operators/addition-operator.md index 9774edd615841..e36452463a74b 100644 --- a/docs/csharp/language-reference/operators/addition-operator.md +++ b/docs/csharp/language-reference/operators/addition-operator.md @@ -1,6 +1,6 @@ --- title: "+ and += operators - C# reference" -ms.date: 05/24/2019 +ms.date: 04/23/2020 f1_keywords: - "+_CSharpKeyword" - "+=_CSharpKeyword" @@ -22,7 +22,7 @@ For information about the arithmetic `+` operator, see the [Unary plus and minus ## String concatenation -When one or both operands are of type [string](../builtin-types/reference-types.md#the-string-type), the `+` operator concatenates the string representations of its operands: +When one or both operands are of type [string](../builtin-types/reference-types.md#the-string-type), the `+` operator concatenates the string representations of its operands (the string representation of `null` is an empty string): [!code-csharp-interactive[string concatenation](snippets/AdditionOperator.cs#AddStrings)] diff --git a/docs/csharp/language-reference/operators/snippets/AdditionOperator.cs b/docs/csharp/language-reference/operators/snippets/AdditionOperator.cs index 1f0878a56e1af..db376738bef5b 100644 --- a/docs/csharp/language-reference/operators/snippets/AdditionOperator.cs +++ b/docs/csharp/language-reference/operators/snippets/AdditionOperator.cs @@ -26,9 +26,11 @@ private static void StringConcatenation() // Console.WriteLine("Forgot" + "white space"); Console.WriteLine("Probably the oldest constant: " + Math.PI); + Console.WriteLine(null + "Nothing to add."); // Output: // Forgotwhite space // Probably the oldest constant: 3.14159265358979 + // Nothing to add. // // diff --git a/docs/csharp/language-reference/operators/snippets/Program.cs b/docs/csharp/language-reference/operators/snippets/Program.cs index 8b1879f90162d..fc1cb4e9879d1 100644 --- a/docs/csharp/language-reference/operators/snippets/Program.cs +++ b/docs/csharp/language-reference/operators/snippets/Program.cs @@ -103,7 +103,7 @@ static async Task Main(string[] args) UserDefinedConversions.Main(); Console.WriteLine(); - Console.WriteLine("========= switch expression example ========="); + Console.WriteLine("========= switch expression example ============"); SwitchExpressions.Examples(); Console.WriteLine();