Byte.Equals Byte.Equals Byte.Equals Byte.Equals Method

定义

返回一个值,该值指示 Byte 的两个实例是否表示同一个值。Returns a value indicating whether two instances of Byte represent the same value.

重载

Equals(Byte) Equals(Byte) Equals(Byte) Equals(Byte)

返回一个值,该值指示此实例和指定的 Byte 对象是否表示相同的值。Returns a value indicating whether this instance and a specified Byte object represent the same value.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例是否等于指定的对象。Returns a value indicating whether this instance is equal to a specified object.

Equals(Byte) Equals(Byte) Equals(Byte) Equals(Byte)

返回一个值,该值指示此实例和指定的 Byte 对象是否表示相同的值。Returns a value indicating whether this instance and a specified Byte object represent the same value.

public:
 virtual bool Equals(System::Byte obj);
public bool Equals (byte obj);
override this.Equals : byte -> bool
Public Function Equals (obj As Byte) As Boolean

参数

obj
Byte Byte Byte Byte

要与此实例进行比较的对象。An object to compare to this instance.

返回

如果 true 与此实例相等,则为 obj;否则为 falsetrue if obj is equal to this instance; otherwise, false.

实现

示例

下面的代码Byte示例确定第一个值是否等于第二个Byte值,以及第一个Byte值是否等于第二个Byte值的装箱版本。The following code example determines whether the first Byte value is equal to the second Byte value, and whether the first Byte value is equal to the boxed version of the second Byte value.

using namespace System;

void main()
{
    Byte   byteVal1 = 0x7f;
    Byte   byteVal2 = 127;
    Object^ objectVal3 = byteVal2;

    Console::WriteLine("byteVal1 = {0}, byteVal2 = {1}, objectVal3 = {2}\n",
                       byteVal1, byteVal2, objectVal3);
    Console::WriteLine("byteVal1 equals byteVal2?: {0}", byteVal1.Equals(byteVal2));
    Console::WriteLine("byteVal1 equals objectVal3?: {0}", byteVal1.Equals(objectVal3));
}
/*
This example displays the following output:
      byteVal1 = 127, byteVal2 = 127, objectVal3 = 127

      byteVal1 equals byteVal2?: True
      byteVal1 equals objectVal3?: True
*/
// This code example demonstrates the System.Byte.Equals(Object) and
// System.Byte.Equals(Byte) methods.

using System;

class Sample 
{
    public static void Main() 
    {
    byte   byteVal1 = 0x7f;
    byte   byteVal2 = 127;
    object objectVal3 = byteVal2;
//
    Console.WriteLine("byteVal1 = {0}, byteVal2 = {1}, objectVal3 = {2}\n",
                       byteVal1, byteVal2, objectVal3);
    Console.WriteLine("byteVal1 equals byteVal2?: {0}", byteVal1.Equals(byteVal2));
    Console.WriteLine("byteVal1 equals objectVal3?: {0}", byteVal1.Equals(objectVal3));
    }
}

/*
This code example produces the following results:

byteVal1 = 127, byteVal2 = 127, objectVal3 = 127

byteVal1 equals byteVal2?: True
byteVal1 equals objectVal3?: True

*/
' This code example demonstrates the System.Byte.Equals(Object) and
' System.Byte.Equals(Byte) methods.

Class Sample
    Public Shared Sub Main() 
        Dim byteVal1 As Byte = &H7F
        Dim byteVal2 As Byte = 127
        Dim objectVal3 As Object = byteVal2
        '
        Console.WriteLine("byteVal1 = {0}, byteVal2 = {1}, objectVal3 = {2}" & vbCrLf, _
                          byteVal1, byteVal2, objectVal3)
        Console.WriteLine("byteVal1 equals byteVal2?: {0}", byteVal1.Equals(byteVal2))
        Console.WriteLine("byteVal1 equals objectVal3?: {0}", byteVal1.Equals(objectVal3))
    End Sub
End Class

'
'This code example produces the following results:
'
'byteVal1 = 127, byteVal2 = 127, objectVal3 = 127
'
'byteVal1 equals byteVal2?: True
'byteVal1 equals objectVal3?: True
'

注解

此方法实现接口System.IEquatable<T> ,并且执行的Equals(Object)效果略优于,因为obj无需将参数转换为对象。This method implements the System.IEquatable<T> interface, and performs slightly better than Equals(Object) because it does not have to convert the obj parameter to an object.

另请参阅

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例是否等于指定的对象。Returns a value indicating whether this instance is equal to a specified object.

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

参数

obj
Object Object Object Object

与此实例进行比较的对象,或为 nullAn object to compare with this instance, or null.

返回

如果 trueobj 的实例并且等于此实例的值,则为 Byte;否则为 falsetrue if obj is an instance of Byte and equals the value of this instance; otherwise, false.

示例

下面的代码Byte示例确定第一个值是否等于第二个Byte值,以及第一个Byte值是否等于第二个Byte值的装箱版本。The following code example determines whether the first Byte value is equal to the second Byte value, and whether the first Byte value is equal to the boxed version of the second Byte value.

using namespace System;

void main()
{
    Byte   byteVal1 = 0x7f;
    Byte   byteVal2 = 127;
    Object^ objectVal3 = byteVal2;

    Console::WriteLine("byteVal1 = {0}, byteVal2 = {1}, objectVal3 = {2}\n",
                       byteVal1, byteVal2, objectVal3);
    Console::WriteLine("byteVal1 equals byteVal2?: {0}", byteVal1.Equals(byteVal2));
    Console::WriteLine("byteVal1 equals objectVal3?: {0}", byteVal1.Equals(objectVal3));
}
/*
This example displays the following output:
      byteVal1 = 127, byteVal2 = 127, objectVal3 = 127

      byteVal1 equals byteVal2?: True
      byteVal1 equals objectVal3?: True
*/
// This code example demonstrates the System.Byte.Equals(Object) and
// System.Byte.Equals(Byte) methods.

using System;

class Sample 
{
    public static void Main() 
    {
    byte   byteVal1 = 0x7f;
    byte   byteVal2 = 127;
    object objectVal3 = byteVal2;
//
    Console.WriteLine("byteVal1 = {0}, byteVal2 = {1}, objectVal3 = {2}\n",
                       byteVal1, byteVal2, objectVal3);
    Console.WriteLine("byteVal1 equals byteVal2?: {0}", byteVal1.Equals(byteVal2));
    Console.WriteLine("byteVal1 equals objectVal3?: {0}", byteVal1.Equals(objectVal3));
    }
}

/*
This code example produces the following results:

byteVal1 = 127, byteVal2 = 127, objectVal3 = 127

byteVal1 equals byteVal2?: True
byteVal1 equals objectVal3?: True

*/
' This code example demonstrates the System.Byte.Equals(Object) and
' System.Byte.Equals(Byte) methods.

Class Sample
    Public Shared Sub Main() 
        Dim byteVal1 As Byte = &H7F
        Dim byteVal2 As Byte = 127
        Dim objectVal3 As Object = byteVal2
        '
        Console.WriteLine("byteVal1 = {0}, byteVal2 = {1}, objectVal3 = {2}" & vbCrLf, _
                          byteVal1, byteVal2, objectVal3)
        Console.WriteLine("byteVal1 equals byteVal2?: {0}", byteVal1.Equals(byteVal2))
        Console.WriteLine("byteVal1 equals objectVal3?: {0}", byteVal1.Equals(objectVal3))
    End Sub
End Class

'
'This code example produces the following results:
'
'byteVal1 = 127, byteVal2 = 127, objectVal3 = 127
'
'byteVal1 equals byteVal2?: True
'byteVal1 equals objectVal3?: True
'
另请参阅

适用于