Export (0) Print
Expand All

Byte.CompareTo Method

Compares this instance to a specified object and returns an indication of their relative values.

[Visual Basic]
Public Overridable Function CompareTo( _
   ByVal value As Object _
) As Integer
[C#]
public virtual int CompareTo(
 object value
);
[C++]
public: virtual int CompareTo(
 Object* value
);
[JScript]
public function CompareTo(
   value : Object
) : int;

Parameters

value
An object to compare, or a null reference (Nothing in Visual Basic).

Return Value

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 a null reference (Nothing in Visual Basic).

Exceptions

Exception Type Condition
ArgumentException value is not a Byte.

Remarks

value must be a null reference (Nothing in Visual Basic) or an instance of Byte; otherwise, an exception is thrown.

Any instance of Byte, regardless of its value, is considered greater than a null reference (Nothing).

This method is implemented to support the IComparable interface.

Example

[Visual Basic] 
Public Sub Compare(ByVal myByte As [Byte])
   Dim myCompareResult As Integer

   myCompareResult = MemberByte.CompareTo(myByte)

   If myCompareResult > 0 Then
      Console.WriteLine("{0} is less than the MemberByte value {1}", myByte.ToString(), MemberByte.ToString())
   Else
      If myCompareResult < 0 Then
         Console.WriteLine("{0} is greater than the MemberByte value {1}", myByte.ToString(), MemberByte.ToString())
      Else
         Console.WriteLine("{0} is equal to the MemberByte value {1}", myByte.ToString(), MemberByte.ToString())
      End If
   End If
End Sub 'Compare 

[C#] 
public void Compare(Byte myByte)
{
   int myCompareResult;
  
   myCompareResult = MemberByte.CompareTo(myByte);

   if(myCompareResult > 0)
   {
      Console.WriteLine("{0} is less than the MemberByte value {1}", myByte.ToString(), MemberByte.ToString());
   }
   else if(myCompareResult < 0)
   {
      Console.WriteLine("{0} is greater than the MemberByte value {1}", myByte.ToString(), MemberByte.ToString());
   }
   else
   {
      Console.WriteLine("{0} is equal to the MemberByte value {1}", myByte.ToString(), MemberByte.ToString());
   }
}

[C++] 
void Compare(Byte myByte)
{
    Int32 myCompareResult;
  
    myCompareResult = MemberByte.CompareTo(__box(myByte));

    if(myCompareResult > 0){
        Console::WriteLine("{0} is less than the MemberByte value {1}", myByte.ToString(), MemberByte.ToString());
    }
    else{
        if(myCompareResult < 0)
            Console::WriteLine("{0} is greater than the MemberByte value {1}", myByte.ToString(), MemberByte.ToString());
        else
            Console::WriteLine("{0} is equal to the MemberByte value {1}", myByte.ToString(), MemberByte.ToString());
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Byte Structure | Byte Members | System Namespace | ArgumentException | IComparable | Equals

Show:
© 2014 Microsoft