Decimal.op_UnaryNegation 메서드
지정된 Decimal 피연산자 값의 부정입니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Shared Operator - ( _
d As Decimal _
) As Decimal
‘사용 방법
Dim d As Decimal
Dim returnValue As Decimal
returnValue = -d
public static decimal operator - (
decimal d
)
public:
static Decimal operator - (
Decimal d
)
J#에서는 오버로드된 연산자를 지원하지 않습니다.
JScript에서는 오버로드된 연산자를 사용할 수 있지만 새로 선언할 수는 없습니다.
매개 변수
- d
피연산자 Decimal입니다.
반환 값
d에 -1을 곱한 결과입니다.
예제
다음 코드 예제에서는 Unary Negation 연산자를 몇 개의 Decimal 값에 적용합니다.
' Example of the Decimal increment, decrement, unary negation, and
' unary plus operators.
Imports System
Imports Microsoft.VisualBasic
Module DecIncrDecrUnaryDemo
' Get the exception type name; remove the namespace prefix.
Function GetExceptionType( 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( argument as Decimal )
Dim toBeIncr As Decimal = argument
Dim toBeDecr As Decimal = argument
Console.WriteLine( "{0,-36}{1}", "Decimal argument: ", _
argument )
' The op_Increment and op_Decrement operators must be
' explicitly coded in Visual Basic.
' Catch the exception if the increment operator throws one.
Console.Write( "{0,-36}", "Decimal.op_Increment( argument )" )
Try
toBeIncr = Decimal.op_Increment( toBeIncr )
Console.WriteLine( "{0}", toBeIncr )
Catch ex As Exception
Console.WriteLine( "{0}", GetExceptionType( ex ) )
End Try
' Catch the exception if the decrement operator throws one.
Console.Write( "{0,-36}", "Decimal.op_Decrement( argument )" )
Try
toBeDecr = Decimal.op_Decrement( toBeDecr )
Console.WriteLine( "{0}", toBeDecr )
Catch ex As Exception
Console.WriteLine( "{0}", GetExceptionType( ex ) )
End Try
Console.WriteLine( )
End Sub
Sub Main( )
Console.WriteLine( _
"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 )
' Create objects to compare with the reference.
DecIncrDecrUnary( 0.000000123D )
DecIncrDecrUnary( 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( Decimal.op_UnaryNegation( _
New Decimal( 123000000, 0, 0, false, 9 ) ) )
DecIncrDecrUnary( Decimal.op_UnaryPlus( Decimal.MaxValue ) )
DecIncrDecrUnary( Decimal.op_UnaryNegation( Decimal.MaxValue ) )
DecIncrDecrUnary( 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
// Example of the decimal increment, decrement, unary negation, and
// unary plus operators.
using System;
class DecIncrDecrUnaryDemo
{
// Get the exception type name; remove the namespace prefix.
public static string GetExceptionType( Exception ex )
{
string exceptionType = ex.GetType( ).ToString( );
return exceptionType.Substring(
exceptionType.LastIndexOf( '.' ) + 1 );
}
// Display the argument and the incremented and decremented values.
public static 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( );
}
public static void 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( 0.000000123M );
DecIncrDecrUnary( new decimal( 123000000, 0, 0, false, 9 ) );
DecIncrDecrUnary( - new decimal( 123000000, 0, 0, false, 9 ) );
DecIncrDecrUnary( + decimal.MaxValue );
DecIncrDecrUnary( - decimal.MaxValue );
DecIncrDecrUnary( + 7.5000000000000000000000000001M );
}
}
/*
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
*/
// 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
*/
// Example of the decimal increment, decrement, unary negation, and
// unary plus operators.
import System.*;
class DecIncrDecrUnaryDemo
{
// Get the exception type name; remove the namespace prefix.
public static String GetExceptionType(Exception ex)
{
String exceptionType = ex.GetType().ToString();
return exceptionType.Substring((exceptionType.LastIndexOf('.') + 1));
} //GetExceptionType
// Display the argument and the incremented and decremented values.
public static void DecIncrDecrUnary(System.Decimal argument)
{
System.Decimal toBeIncr = argument;
System.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 =System.Decimal.Add(toBeIncr,System.Convert.ToDecimal(1));
Console.WriteLine("{0}", toBeIncr);
}
catch(System.Exception ex){
Console.WriteLine("{0}",(ex.GetType()));
}
// Catch the exception if the decrement operator throws one.
Console.Write("{0,-26}", "argument --");
try {
toBeDecr= System.Decimal.Subtract(toBeIncr,
System.Convert.ToDecimal(1));
Console.WriteLine("{0}", toBeDecr);
}
catch(System.Exception ex){
Console.WriteLine("{0}", (ex.GetType()));
}
Console.WriteLine();
} //DecIncrDecrUnary
public static void main(String[] args)
{
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(System.Convert.ToDecimal(0.000000123));
DecIncrDecrUnary(new System.Decimal(123000000, 0, 0, false,
System.Convert.ToByte(9)));
DecIncrDecrUnary(System.Decimal.Negate(new System.Decimal(123000000,
0, 0, false,System.Convert.ToByte(9))));
DecIncrDecrUnary(System.Decimal.MaxValue);
DecIncrDecrUnary(System.Decimal.Negate(System.Decimal.MaxValue));
DecIncrDecrUnary(System.Convert.ToDecimal
(7.5000000000000000000000000001));
} //main
} //DecIncrDecrUnaryDemo
/*
decimal argument: 0.000000123
argument ++ 1.000000123
argument -- 0.000000123
decimal argument: 0.123000000
argument ++ 1.123000000
argument -- 0.123000000
decimal argument: -0.123000000
argument ++ 0.877000000
argument -- -0.123000000
decimal argument: 79228162514264337593543950335
argument ++ System.OverflowException
argument -- 79228162514264337593543950334
decimal argument: -79228162514264337593543950335
argument ++ -79228162514264337593543950334
argument -- -79228162514264337593543950335
decimal argument: 7.5
argument ++ 8.5
argument -- 7.5
*/
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원