指定したオブジェクトとこのインスタンスを比較し、これらの相対値を示す値を返します。
Public Overridable Function CompareTo( _
ByVal value As Object _) As Integer
[C#]
public virtual int CompareTo(objectvalue);
[C++]
public: virtual int CompareTo(Object* value);
[JScript]
public function CompareTo(
value : Object) : int;
パラメータ
- value
比較対象のオブジェクト、または null 参照 (Visual Basic では Nothing) 。
戻り値
このインスタンスと value の相対値を示す符号付き整数。
戻り値 | 説明 |
---|---|
0 より小さい値 | このインスタンスは value よりも小さくなっています。 |
0 | このインスタンスは value と等価です。 |
0 より大きい値 | このインスタンスは value よりも大きくなっています。
または value が null 参照 (Visual Basic では Nothing) です。 |
例外
例外の種類 | 条件 |
---|---|
ArgumentException | value が Byte ではありません。 |
解説
value は null 参照 (Visual Basic では Nothing) であるか、または Byte のインスタンスである必要があります。それ以外の場合は、例外がスローされます。
Byte のすべてのインスタンスは、その値に関係なく、 null 参照 (Nothing) より大きいと見なされます。
このメソッドは、 IComparable インターフェイスをサポートするために実装します。
使用例
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
Byte 構造体 | Byte メンバ | System 名前空間 | ArgumentException | IComparable | Equals