Decimal.Add() Method in C#


The Decimal.Add() method in C# is used to add two specified Decimal values.

Syntax

Following is the syntax −

public static decimal Add (decimal val1, decimal val2);

Above, va1 is the first decimal to add, whereas val2 is the second decimal to be added.

Example

Let us now see an example to implement the Decimal.Add() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = 3.07m;
      Decimal val2 = 4.09m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Decimal res = Decimal.Add(val1, val2);
      Console.WriteLine("Result (Sum) = "+res);
   }
}

Output

This will produce the following output −

Decimal 1 = 3.07
Decimal 2 = 4.09
Result (Sum) = 7.16

Example

Let us now see another example to implement the Decimal.Add() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val1 = Decimal.MinValue;
      Decimal val2 = 8.21m;
      Console.WriteLine("Decimal 1 = "+val1);
      Console.WriteLine("Decimal 2 = "+val2);
      Decimal res = Decimal.Add(val1, val2);
      Console.WriteLine("Result (Sum) = "+res);
   }
}

Output

This will produce the following output −

Decimal 1 = -79228162514264337593543950335
Decimal 2 = 8.21
Result (Sum) = -79228162514264337593543950327

Updated on: 12-Nov-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements