Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#의 Decimal.Negate() 메서드

<시간/>

C#의 Decimal.Negate() 메서드는 지정된 Decimal 값에 음수를 곱한 결과를 반환하는 데 사용됩니다.

구문

다음은 구문입니다 -

public static decimal Negate (decimal val);

위의 Val은 부정할 값입니다.

이제 Decimal.Negate() 메서드를 구현하는 예를 살펴보겠습니다. -

using System;
public class Demo {
   public static void Main(){
      Decimal val = 3972.491M;
      Console.WriteLine("Decimal Value = {0}", val);
      Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );
      TypeCode type = val.GetTypeCode();
      Console.WriteLine("TypeCode = "+type);
      Decimal res = Decimal.Negate(val);
      Console.WriteLine("Negative (Decimal) = "+res);
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Decimal Value = 3972.491
HashCode = 620041307
TypeCode = Decimal
Negative (Decimal) = -3972.491

이제 Decimal.Negate() 메서드를 구현하는 또 다른 예를 살펴보겠습니다. -

using System;
public class Demo {
   public static void Main(){
      Decimal val = -29.35m;
      Console.WriteLine("Decimal Value = {0}", val);
      Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );
      TypeCode type = val.GetTypeCode();
      Console.WriteLine("TypeCode = "+type);
      Decimal res = Decimal.Negate(val);
      Console.WriteLine("Negative (Decimal) = "+res);
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Decimal Value = -29.35
HashCode = 1503969289
TypeCode = Decimal
Negative (Decimal) = 29.35