C# Int32 CompareTo(Int32)

Description

Int32 CompareTo(Int32) compares this instance to a specified 32-bit signed integer and returns an indication of their relative values.

Syntax

Int32.CompareTo(Int32) has the following syntax.


public int CompareTo(
  int value
)

Parameters

Int32.CompareTo(Int32) has the following parameters.

  • value - An integer to compare.

Returns

Int32.CompareTo(Int32) 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 example demonstrates the Int32.CompareTo(Int32) method.


using System;/*from   w w  w. j a  v a 2  s .co m*/

public class ValueComparison
{
   public static void Main()
   {
      int mainValue = 16325;
      int zeroValue = 0;

      Console.WriteLine(mainValue.CompareTo(zeroValue));

   }
}

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