Decimal.Compare() Method in C# Last Updated : 29 Jan, 2019 Comments Improve Suggest changes Like Article Like Report This method is used to compare two specified Decimal values. Syntax: public static int Compare (decimal a1, decimal a2); Parameters: a1:This parameter specifies the first value to compare. a2:This parameter specifies the second value to compare. Return Value: It returns a signed number indicating the relative values of a1 & a2. If the value is less than zero, it means a1 is less than a2. If the value is greater than zero, it means a1 is greater than a2. If the value is zero, it means a1 is equal to a2. Below programs illustrate the use of Decimal.Compare(Decimal, Decimal) Method Example 1: When a1 is greater than a2. csharp // C# program to demonstrate the // Decimal.Compare(Decimal, // Decimal) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring the decimal variables Decimal a1 = 4; Decimal a2 = 3; // comparing the two Decimal value // using Compare() method; Decimal value = Decimal.Compare(a1, a2); // Display the compare value Console.WriteLine("The compare value is : {0}", value); } } Output: The compare value is : 1 Example 2: When a1 is less than a2. csharp // C# program to demonstrate the // Decimal.Compare(Decimal, // Decimal) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring the decimal variables Decimal a1 = 1; Decimal a2 = 9; // comparing the two Decimal value // using Compare() method; Decimal value = Decimal.Compare(a1, a2); // Display the compare value Console.WriteLine("The compare value is : {0}", value); } } Output: The compare value is : -1 Example 3: When a1 is equals to a2. csharp // C# program to demonstrate the // Decimal.Compare(Decimal, // Decimal) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring the decimal variables Decimal a1 = 5; Decimal a2 = 5; // comparing the two Decimal value // using Compare() method; Decimal value = Decimal.Compare(a1, a2); // Display the compare value Console.WriteLine("The compare value is : {0}", value); } } Output: The compare value is : 0 Comment More infoAdvertise with us Next Article Decimal.Compare() Method in C# I IshwarGupta Follow Improve Article Tags : C# CSharp-method CSharp-Decimal-Struct Similar Reads Decimal.CompareTo() Method in C# This method is used to compare the current instance to a specified object or Decimal and returns an indication of their relative values. There are 2 methods in the overload list of this method as follows: CompareTo(Decimal) MethodCompareTo(Object) MethodDecimal.CompareTo(Decimal) Method This method 4 min read DateTime.Compare() Method in C# This method is used to compare two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance. Syntax: public static int Compare (DateTime t1, DateTime t2); Parameters: t1: The first object to compare. t2: Th 2 min read DateTime.CompareTo() Method in C# This method is used to compare the value of this instance to a specified DateTime value and indicates whether this instance is earlier than, the same as, or later than the specified DateTime value. There are two methods in the overload list of this method as follows: CompareTo(DateTime) CompareTo(Ob 3 min read DateTimeOffset.Compare() Method in C# DateTimeOffset.Compare(DateTimeOffset, DateTimeOffset) Method is used to compare two DateTimeOffset objects and shows whether the first is earlier than the second, equal to the second, or later than the second. Syntax: public static int Compare (DateTimeOffset first, DateTimeOffset second); Paramete 2 min read Int16.CompareTo() Method in C# Int16.CompareTo Method is used to compare the current instance to a specified object or another Int16 instance. It returns an integer which shows whether the value of the current instance is less than, equal to, or greater than the value of the specified object or the other Int16 instance. There are 4 min read Like