![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements