C# Int16 CompareTo(Object)
Description
Int16 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 object.
Syntax
Int16.CompareTo(Object)
has the following syntax.
public int CompareTo(
Object value
)
Parameters
Int16.CompareTo(Object)
has the following parameters.
value
- An object to compare, or null.
Returns
Int16.CompareTo(Object)
method returns A signed number indicating the relative values of this instance and value.
Return Value Description 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. -or- value is null.
Example
The following code example demonstrates the CompareTo method.
using System;/* ww w . ja v a2s .c o m*/
class Sample
{
public static void Main()
{
Int16 c1 = -2, c2 = 2;
try {
Console.WriteLine(c1.CompareTo((Object)c2));
}catch (Exception e){
Console.WriteLine(e);
}
}
}
The code above generates the following result.