System.UInt16.CompareTo Method

Compares this instance to a specified 16-bit unsigned integer and returns an indication of their relative values.

Syntax

public int CompareTo (ushort value)

Parameters

value
An unsigned integer to compare.

Returns

A signed number indicating the relative values of this instance and value.

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.

Remarks

This method implements the IComparable`1 interface and performs slightly better than the ushort.CompareTo(object) method because it does not have to convert the value parameter to an object.

Depending on your programming language, it might be possible to code a erload:System.UInt16.CompareTo method where the parameter type has fewer bits (is narrower) than the instance type. This is possible because some programming languages perform an implicit widening conversion that represents the parameter as a type with as many bits as the instance.

For example, suppose the instance type is int and the parameter type is byte. The Microsoft C# compiler generates instructions to represent the value of the parameter as an int object, then generates a int.CompareTo(object) method that compares the values of the int instance and the int parameter representation.

Consult your programming language's documentation to determine whether its compiler performs implicit widening conversions on numeric types.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0