Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

53 changes: 37 additions & 16 deletions docs/csharp/language-reference/operators/decrement-operator.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "-- Operator (C# Reference)"
ms.date: 07/20/2015
ms.date: 11/26/2018
f1_keywords:
- "--_CSharpKeyword"
helpviewer_keywords:
Expand All @@ -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)
55 changes: 37 additions & 18 deletions docs/csharp/language-reference/operators/increment-operator.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "++ Operator (C# Reference)"
ms.date: 07/20/2015
ms.date: 11/26/2018
f1_keywords:
- "++_CSharpKeyword"
helpviewer_keywords:
Expand All @@ -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)