C# Int16 CompareTo(Int16)

Description

Int16 CompareTo(Int16) compares this instance to a specified 16-bit signed integer 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 16-bit signed integer.

Syntax

Int16.CompareTo(Int16) has the following syntax.


public int CompareTo(
  short value
)

Parameters

Int16.CompareTo(Int16) has the following parameters.

  • value - An integer to compare.

Returns

Int16.CompareTo(Int16) 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.

Example

The following code example demonstrates the CompareTo method.


using System;/*  www .  ja va 2s.co  m*/

class Sample 
{
    public static void Main() 
    {
        Int16    c1 = -2,    c2 = 2;
        try {
            Console.WriteLine(c1.CompareTo(c2));
        }catch (Exception e){
            Console.WriteLine(e);
        }
    }
}

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