Byte.Equals Metodo

Definizione

Restituisce un valore che indica se due istanze di Byte rappresentano lo stesso valore.

Overload

Nome Descrizione
Equals(Byte)

Restituisce un valore che indica se questa istanza e un oggetto specificato Byte rappresentano lo stesso valore.

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

Esempio

Nell'esempio di codice seguente viene determinato se il primo Byte valore è uguale al secondo Byte valore e se il primo Byte valore è uguale alla versione boxed del secondo Byte valore.

// 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

*/
let byteVal1 = 0x7fuy
let byteVal2 = 127uy
let objectVal3: obj = byteVal2

printfn $"byteVal1 = {byteVal1}, byteVal2 = {byteVal2}, objectVal3 = {objectVal3}\n"
printfn $"byteVal1 equals byteVal2?: {byteVal1.Equals byteVal2}"
printfn $"byteVal1 equals objectVal3?: {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
'

Equals(Byte)

Restituisce un valore che indica se questa istanza e un oggetto specificato Byte rappresentano lo stesso valore.

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

Parametri

obj
Byte

Oggetto da confrontare con questa istanza.

Valori restituiti

true se obj è uguale a questa istanza; in caso contrario, false.

Implementazioni

Commenti

Questo metodo implementa l'interfaccia System.IEquatable<T> ed esegue prestazioni leggermente migliori rispetto Equals(Object) a perché non è necessario convertire il obj parametro in un oggetto .

Vedi anche

Si applica a

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

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

Parametri

obj
Object

Oggetto da confrontare con questa istanza o null.

Valori restituiti

true se obj è un'istanza di Byte e è uguale al valore di questa istanza; in caso contrario, false.

Vedi anche

Si applica a