This documentation is archived and is not being maintained.
Decimal::UnaryPlus Operator
Visual Studio 2010
Returns the value of the Decimal operand (the sign of the operand is unchanged).
Assembly: mscorlib (in mscorlib.dll)
Parameters
- d
- Type: System::Decimal
The operand to return.
The following code example applies the Unary Plus operator to several Decimal values.
// Example of the Decimal increment, decrement, unary negation, and // unary plus operators. using namespace System; // Get the exception type name; remove the namespace prefix. String^ GetExceptionType( Exception^ ex ) { String^ exceptionType = ex->GetType()->ToString(); return exceptionType->Substring( exceptionType->LastIndexOf( '.' ) + 1 ); } // Display the argument and the incremented and decremented values. void DecIncrDecrUnary( Decimal argument ) { Decimal toBeIncr = argument; Decimal toBeDecr = argument; Console::WriteLine( "{0,-26}{1}", "Decimal argument: ", argument ); // Catch the exception if the increment operator throws one. Console::Write( "{0,-26}", "argument ++" ); try { toBeIncr++; Console::WriteLine( "{0}", toBeIncr ); } catch ( Exception^ ex ) { Console::WriteLine( "{0}", GetExceptionType( ex ) ); } // Catch the exception if the decrement operator throws one. Console::Write( "{0,-26}", "argument --" ); try { toBeDecr--; Console::WriteLine( "{0}", toBeDecr ); } catch ( Exception^ ex ) { Console::WriteLine( "{0}", GetExceptionType( ex ) ); } Console::WriteLine(); } int main() { Console::WriteLine( "This example of the Decimal increment, " "decrement, unary negation, \nand unary plus operators " "generates the following output. It \ndisplays the " "results of the operators on several Decimal values.\n" ); // Create objects to compare with the reference. DecIncrDecrUnary( Decimal::Parse( "0.000000123" ) ); DecIncrDecrUnary( Decimal(123000000,0,0,false,9) ); DecIncrDecrUnary( -Decimal(123000000,0,0,false,9) ); DecIncrDecrUnary( +Decimal::MaxValue ); DecIncrDecrUnary( -Decimal::MaxValue ); DecIncrDecrUnary( +Decimal::Parse( "7.5000000000000000000000000001" ) ); } /* 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 argument ++ 1.000000123 argument -- -0.999999877 Decimal argument: 0.123000000 argument ++ 1.123000000 argument -- -0.877000000 Decimal argument: -0.123000000 argument ++ 0.877000000 argument -- -1.123000000 Decimal argument: 79228162514264337593543950335 argument ++ OverflowException argument -- 79228162514264337593543950334 Decimal argument: -79228162514264337593543950335 argument ++ -79228162514264337593543950334 argument -- OverflowException Decimal argument: 7.5000000000000000000000000001 argument ++ 8.500000000000000000000000000 argument -- 6.5000000000000000000000000001 */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: