C# Double CompareTo(Object)
Description
Double CompareTo(Object)
compares this instance to
a specified object and returns an integer that indicates whether the value
of this instance is less than, equal to, or greater than the value of the specified
object.
Syntax
Double.CompareTo(Object)
has the following syntax.
public int CompareTo(
Object value
)
Parameters
Double.CompareTo(Object)
has the following parameters.
value
- An object to compare, or null.
Returns
Double.CompareTo(Object)
method returns A signed number indicating the relative values of this instance and value.
Value Description A negative integer This instance is less than value. -or-
This instance is not a number (NaN) and value is a number. Zero This instance
is equal to value. -or- This instance and value are both Double.NaN, PositiveInfinity,
or NegativeInfinity A positive integer This instance is greater than value.
-or- This instance is a number and value is not a number (NaN). -or- value is
null.
Example
The following code shows how to use Double.CompareTo(Object)
method.
using System;/* w ww.j ava 2s .c om*/
public class Example
{
public static void Main()
{
double value1 = 6.185;
object value2 = value1 * .1 / .1;
Console.WriteLine("Comparing {0} and {1}: {2}\n",
value1, value2, value1.CompareTo(value2));
Console.WriteLine("Comparing {0:R} and {1:R}: {2}",
value1, value2, value1.CompareTo(value2));
}
}
The code above generates the following result.