Decimal.Increment Operator

July 28, 2014

Increments the Decimal operand by 1.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Shared Operator ++ ( _
	d As Decimal _
) As Decimal

Parameters

d
Type: System.Decimal
The Decimal operand.

Return Value

Type: System.Decimal
The value of d incremented by 1.

ExceptionCondition
OverflowException

The return value is less than MinValue or greater than MaxValue.

The following code example applies the Increment operator to several Decimal values.


' Example of the Decimal increment, decrement, unary negation, and 
' unary plus operators.

Module Example

   ' Get the exception type name; remove the namespace prefix.
   Function GetExceptionType(ByVal ex As Exception) As String

      Dim exceptionType As String = ex.GetType().ToString()
      Return exceptionType.Substring( _
          exceptionType.LastIndexOf("."c) + 1)
   End Function

   ' Display the argument and the incremented and decremented values.
   Sub DecIncrDecrUnary(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal argument As Decimal)

      Dim toBeIncr As Decimal = argument
      Dim toBeDecr As Decimal = argument

      outputBlock.Text &= String.Format("{0,-36}{1}", "Decimal argument: ", _
          argument) & vbCrLf

      ' The op_Increment and op_Decrement operators must be 
      ' explicitly coded in Visual Basic.

      ' Catch the exception if the increment operator throws one.
      outputBlock.Text &= String.Format("{0,-36}", "Decimal.op_Increment( argument )")
      Try
         toBeIncr = Decimal.op_Increment(toBeIncr)
         outputBlock.Text &= String.Format("{0}", toBeIncr) & vbCrLf
      Catch ex As Exception
         outputBlock.Text &= String.Format("{0}", GetExceptionType(ex)) & vbCrLf
      End Try

      ' Catch the exception if the decrement operator throws one.
      outputBlock.Text &= String.Format("{0,-36}", "Decimal.op_Decrement( argument )")
      Try
         toBeDecr = Decimal.op_Decrement(toBeDecr)
         outputBlock.Text &= String.Format("{0}", toBeDecr) & vbCrLf
      Catch ex As Exception
         outputBlock.Text &= String.Format("{0}", GetExceptionType(ex)) & vbCrLf
      End Try

      outputBlock.Text &= vbCrLf
   End Sub

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.Text &= String.Format( _
          "This example of the Decimal increment, decrement, " & _
          "unary negation, " & vbCrLf & "and unary plus " & _
          "operators generates the following output. It " & vbCrLf & _
          "displays the results of the operators on several " & _
          "Decimal values." & vbCrLf) & vbCrLf

      ' Create objects to compare with the reference.
      DecIncrDecrUnary(outputBlock, 0.000000123D)
      DecIncrDecrUnary(outputBlock, New Decimal(123000000, 0, 0, False, 9))

      ' The op_UnaryNegation and op_UnaryPlus operators must be
      ' explicitly coded in Visual Basic. If unary + or - is used,
      ' other methods are called.
      DecIncrDecrUnary(outputBlock, Decimal.op_UnaryNegation( _
          New Decimal(123000000, 0, 0, False, 9)))
      DecIncrDecrUnary(outputBlock, Decimal.op_UnaryPlus(Decimal.MaxValue))
      DecIncrDecrUnary(outputBlock, Decimal.op_UnaryNegation(Decimal.MaxValue))
      DecIncrDecrUnary(outputBlock, Decimal.op_UnaryPlus( _
          7.5000000000000000000000000001D))
   End Sub
End Module

' This example of the Decimal increment, decrement, unary negation,
' and unary plus operators generates the following output. It
' displays the results of the operators on several Decimal values.
' 
' Decimal argument:                   0.000000123
' Decimal.op_Increment( argument )    1.000000123
' Decimal.op_Decrement( argument )    -0.999999877
' 
' Decimal argument:                   0.123000000
' Decimal.op_Increment( argument )    1.123000000
' Decimal.op_Decrement( argument )    -0.877000000
' 
' Decimal argument:                   -0.123000000
' Decimal.op_Increment( argument )    0.877000000
' Decimal.op_Decrement( argument )    -1.123000000
' 
' Decimal argument:                   79228162514264337593543950335
' Decimal.op_Increment( argument )    OverflowException
' Decimal.op_Decrement( argument )    79228162514264337593543950334
' 
' Decimal argument:                   -79228162514264337593543950335
' Decimal.op_Increment( argument )    -79228162514264337593543950334
' Decimal.op_Decrement( argument )    OverflowException
' 
' Decimal argument:                   7.5000000000000000000000000001
' Decimal.op_Increment( argument )    8.500000000000000000000000000
' Decimal.op_Decrement( argument )    6.5000000000000000000000000001


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft