From e79c335621285090b1f8ee60af12136d25b6c989 Mon Sep 17 00:00:00 2001 From: pkulikov Date: Fri, 23 Nov 2018 22:13:21 +0100 Subject: [PATCH] Revised increment and decrement operator articles --- .../CSharp/decrement-operator_1.cs | 18 ------ .../CSharp/increment-operator_1.cs | 19 ------- .../operators/decrement-operator.md | 53 ++++++++++++------ .../operators/increment-operator.md | 55 +++++++++++++------ 4 files changed, 74 insertions(+), 71 deletions(-) delete mode 100644 docs/csharp/language-reference/operators/codesnippet/CSharp/decrement-operator_1.cs delete mode 100644 docs/csharp/language-reference/operators/codesnippet/CSharp/increment-operator_1.cs diff --git a/docs/csharp/language-reference/operators/codesnippet/CSharp/decrement-operator_1.cs b/docs/csharp/language-reference/operators/codesnippet/CSharp/decrement-operator_1.cs deleted file mode 100644 index 6d026aa60d339..0000000000000 --- a/docs/csharp/language-reference/operators/codesnippet/CSharp/decrement-operator_1.cs +++ /dev/null @@ -1,18 +0,0 @@ - class MainClass5 - { - static void Main() - { - double x; - x = 1.5; - Console.WriteLine(--x); - x = 1.5; - Console.WriteLine(x--); - Console.WriteLine(x); - } - } - /* - Output: - 0.5 - 1.5 - 0.5 - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/operators/codesnippet/CSharp/increment-operator_1.cs b/docs/csharp/language-reference/operators/codesnippet/CSharp/increment-operator_1.cs deleted file mode 100644 index 21672bac734ef..0000000000000 --- a/docs/csharp/language-reference/operators/codesnippet/CSharp/increment-operator_1.cs +++ /dev/null @@ -1,19 +0,0 @@ - //++ operator - class MainClass - { - static void Main() - { - double x; - x = 1.5; - Console.WriteLine(++x); - x = 1.5; - Console.WriteLine(x++); - Console.WriteLine(x); - } - } - /* - Output - 2.5 - 1.5 - 2.5 - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/operators/decrement-operator.md b/docs/csharp/language-reference/operators/decrement-operator.md index 52d439b912e22..4fe795b3afc61 100644 --- a/docs/csharp/language-reference/operators/decrement-operator.md +++ b/docs/csharp/language-reference/operators/decrement-operator.md @@ -1,6 +1,6 @@ --- title: "-- Operator (C# Reference)" -ms.date: 07/20/2015 +ms.date: 11/26/2018 f1_keywords: - "--_CSharpKeyword" helpviewer_keywords: @@ -9,18 +9,39 @@ helpviewer_keywords: ms.assetid: 6b9cfe86-63c7-421f-9379-c9690fea8720 --- # -- Operator (C# Reference) -The decrement operator (`--`) decrements its operand by 1. The decrement operator can appear before or after its operand: `--variable` and `variable--`. The first form is a prefix decrement operation. The result of the operation is the value of the operand "after" it has been decremented. The second form is a postfix decrement operation. The result of the operation is the value of the operand "before" it has been decremented. - -## Remarks - Numeric and enumeration types have predefined decrement operators. - - User-defined types can overload the `--` operator (see [operator](../../../csharp/language-reference/keywords/operator.md)). Operations on integral types are generally allowed on enumeration. - -## Example - [!code-csharp[csRefOperators#8](../../../csharp/language-reference/operators/codesnippet/CSharp/decrement-operator_1.cs)] - -## See Also - -- [C# Reference](../../../csharp/language-reference/index.md) -- [C# Programming Guide](../../../csharp/programming-guide/index.md) -- [C# Operators](../../../csharp/language-reference/operators/index.md) + +The unary decrement operator `--` decrements its operand by 1. It's supported in two forms: the postfix decrement operator, `x--`, and the prefix decrement operator, `--x`. + +## Postfix decrement operator + +The result of `x--` is the value of `x` *before* the operation, as the following example shows: + +[!code-csharp-interactive[postfix decrement](~/samples/snippets/csharp/language-reference/operators/DecrementAndIncrementExamples.cs#PostfixDecrement)] + +## Prefix decrement operator + +The result of `--x` is the value of `x` *after* the operation, as the following example shows: + +[!code-csharp-interactive[prefix decrement](~/samples/snippets/csharp/language-reference/operators/DecrementAndIncrementExamples.cs#PrefixDecrement)] + +## Remarks + +The decrement operator is predefined for all [integral types](../keywords/integral-types-table.md) (including the [char](../keywords/char.md) type), [floating-point types](../keywords/floating-point-types-table.md), and any [enum](../keywords/enum.md) type. + +An operand of the decrement operator must be a variable, a [property](../../programming-guide/classes-and-structs/properties.md) access, or an [indexer](../../../csharp/programming-guide/indexers/index.md) access. + +## Operator overloadability + +User-defined types can [overload](../keywords/operator.md) the `--` operator. + +## C# language specification + +For more information, see the [Postfix increment and decrement operators](~/_csharplang/spec/expressions.md#postfix-increment-and-decrement-operators) and [Prefix increment and decrement operators](~/_csharplang/spec/expressions.md#prefix-increment-and-decrement-operators) sections of the [C# language specification](../language-specification/index.md). + +## See also + +- [C# Reference](../index.md) +- [C# Programming Guide](../../programming-guide/index.md) +- [C# Operators](index.md) +- [++ Operator](increment-operator.md) +- [How to: increment and decrement pointers](../../programming-guide/unsafe-code-pointers/how-to-increment-and-decrement-pointers.md) diff --git a/docs/csharp/language-reference/operators/increment-operator.md b/docs/csharp/language-reference/operators/increment-operator.md index ed3388e6a6ded..d2011eb37be7e 100644 --- a/docs/csharp/language-reference/operators/increment-operator.md +++ b/docs/csharp/language-reference/operators/increment-operator.md @@ -1,6 +1,6 @@ --- title: "++ Operator (C# Reference)" -ms.date: 07/20/2015 +ms.date: 11/26/2018 f1_keywords: - "++_CSharpKeyword" helpviewer_keywords: @@ -9,20 +9,39 @@ helpviewer_keywords: ms.assetid: e9dec353-070b-44fb-98ed-eb8fdf753feb --- # ++ Operator (C# Reference) -The increment operator (`++`) increments its operand by 1. The increment operator can appear before or after its operand: `++variable` and `variable++`. - -## Remarks - The first form is a prefix increment operation. The result of the operation is the value of the operand after it has been incremented. - - The second form is a postfix increment operation. The result of the operation is the value of the operand before it has been incremented. - - Numeric and enumeration types have predefined increment operators. User-defined types can overload the `++` operator. Operations on integral types are generally allowed on enumeration. - -## Example - [!code-csharp[csRefOperators#3](../../../csharp/language-reference/operators/codesnippet/CSharp/increment-operator_1.cs)] - -## See Also - -- [C# Reference](../../../csharp/language-reference/index.md) -- [C# Programming Guide](../../../csharp/programming-guide/index.md) -- [C# Operators](../../../csharp/language-reference/operators/index.md) + +The unary increment operator `++` increments its operand by 1. It's supported in two forms: the postfix increment operator, `x++`, and the prefix increment operator, `++x`. + +## Postfix increment operator + +The result of `x++` is the value of `x` *before* the operation, as the following example shows: + +[!code-csharp-interactive[postfix increment](~/samples/snippets/csharp/language-reference/operators/DecrementAndIncrementExamples.cs#PostfixIncrement)] + +## Prefix increment operator + +The result of `++x` is the value of `x` *after* the operation, as the following example shows: + +[!code-csharp-interactive[prefix increment](~/samples/snippets/csharp/language-reference/operators/DecrementAndIncrementExamples.cs#PrefixIncrement)] + +## Remarks + +The increment operator is predefined for all [integral types](../keywords/integral-types-table.md) (including the [char](../keywords/char.md) type), [floating-point types](../keywords/floating-point-types-table.md), and any [enum](../keywords/enum.md) type. + +An operand of the increment operator must be a variable, a [property](../../programming-guide/classes-and-structs/properties.md) access, or an [indexer](../../../csharp/programming-guide/indexers/index.md) access. + +## Operator overloadability + +User-defined types can [overload](../keywords/operator.md) the `++` operator. + +## C# language specification + +For more information, see the [Postfix increment and decrement operators](~/_csharplang/spec/expressions.md#postfix-increment-and-decrement-operators) and [Prefix increment and decrement operators](~/_csharplang/spec/expressions.md#prefix-increment-and-decrement-operators) sections of the [C# language specification](../language-specification/index.md). + +## See also + +- [C# Reference](../index.md) +- [C# Programming Guide](../../programming-guide/index.md) +- [C# Operators](index.md) +- [-- Operator](decrement-operator.md) +- [How to: increment and decrement pointers](../../programming-guide/unsafe-code-pointers/how-to-increment-and-decrement-pointers.md)