C# Byte CompareTo(Object)

Description

Byte CompareTo(Object) compares this instance to a specified object and returns an indication of their relative values.

Syntax

Byte.CompareTo(Object) has the following syntax.


public int CompareTo(
  Object value
)

Parameters

Byte.CompareTo(Object) has the following parameters.

  • value - An object to compare, or null.

Returns

Byte.CompareTo(Object) method returns A signed integer that indicates the relative order 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;//w  w  w  .  j a  v a2  s  .  co  m
public class MainClass {
  public static void Main(String[] argv){  
       int myCompareResult;
    
       myCompareResult = 2.CompareTo(1);
    
       if(myCompareResult > 0)
       {
          Console.WriteLine("less than");
       }
       else if(myCompareResult < 0)
       {
          Console.WriteLine("greater than");
       }
       else
       {
          Console.WriteLine("equal to");
       }
  }
}
    

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