C# Decimal CompareTo(Decimal)

Description

Decimal CompareTo(Decimal) compares this instance to a specified Decimal object and returns a comparison of their relative values.

Syntax

Decimal.CompareTo(Decimal) has the following syntax.


public int CompareTo(
  decimal value
)

Parameters

Decimal.CompareTo(Decimal) has the following parameters.

  • value - The object to compare with this instance.

Returns

Decimal.CompareTo(Decimal) method returns A signed number indicating the relative values of this instance and value. Return value Meaning Less than zero This instance is less than value. Zero This instance is equal to value. Greater than zero This instance is greater than value.

Example

The following code example demonstrates nongeneric versions of the CompareTo method.


/* www  .j a va 2 s .  c om*/
using System;

class Sample 
{
    public static void Main() 
    {
        Decimal  f1 = -5.5m, f2 = 5.5m;
        Console.WriteLine(f1.CompareTo(f2));
    }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version