Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CompareTo Method (Object)
Collapse the table of content
Expand the table of content

Byte::CompareTo Method (Object)

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public:
virtual int CompareTo(
	Object^ value
) sealed

Parameters

value
Type: System::Object

An object to compare, or nullptr.

Return Value

Type: System::Int32
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 nullptr.

Implements

IComparable::CompareTo(Object)

ExceptionCondition
ArgumentException

value is not a Byte.

value must be nullptr or an instance of Byte; otherwise, an exception is thrown.

Any instance of Byte, regardless of its value, is considered greater than nullptr.

This method is implemented to support the IComparable interface.

The following code example demonstrates the CompareTo method.

public:
   void Compare( Byte myByte )
   {
      Int32 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() );
      }
   }

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8
Show:
© 2015 Microsoft