- 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.Compare() Method in C#
The Decimal.Compare() method in C# is used to compare two specified Decimal values.
Syntax
Following is the syntax −
public static int Compare (decimal val1, decimal val2);
Above, val1 is the first value to compare, whereas Val is the second value to compare.
The return value is less than zero if val1 is less than val2. Return value is 0, if Val = val2, whereas greater than zero, if val1 is greater than val2.
Example
Let us now see an example to implement the Decimal.Compare() method −
using System; public class Demo { public static void Main(){ Decimal val1 = 45.85m; Decimal val2 = 35.45m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("Comparison Value = "+Decimal.Compare(val1,val2)); } }
Output
This will produce the following output −
Decimal 1 = 45.85 Decimal 2 = 35.45 Comparison Value = 1
Example
Let us now see another example to implement the Decimal.Compare() method −
using System; public class Demo { public static void Main(){ Decimal val1 = 65.15m; Decimal val2 = 65.15m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("Comparison Value = "+Decimal.Compare(val1,val2)); } }
Output
This will produce the following output −
Decimal 1 = 65.15 Decimal 2 = 65.15 Comparison Value = 0
Advertisements