The decimal type is a value type and has the plus, minus, multiply and divide operators.
Firstly, set two decimal values −
decimal d1 = 5.8M; decimal d2 = 3.2M;
To add decimals −
d1 = d1 + d2;
Let us see an example to add two decimal values −
Example
using System;
using System.Linq;
class Demo {
static void Main() {
decimal d1 = 5.8M;
decimal d2 = 3.2M;
d1 = d1 + d2;
Console.WriteLine(d1);
}
}Output
9.0