Byte.Equals Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a value indicating whether two instances of Byte represent the same value.
Equals(Byte) |
Returns a value indicating whether this instance and a specified Byte object represent the same value. |
Equals(Object) |
Returns a value indicating whether this instance is equal to a specified object. |
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
*/
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
'
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
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
Parameters
- obj
- Byte
An object to compare to this instance.
Returns
true
if obj
is equal to this instance; otherwise, false
.
Implements
Remarks
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.
See also
Applies to
.NET 9 和其他版本
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Source:
- Byte.cs
- Source:
- Byte.cs
- Source:
- Byte.cs
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);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean
Parameters
- obj
- Object
An object to compare with this instance, or null
.
Returns
true
if obj
is an instance of Byte and equals the value of this instance; otherwise, false
.
See also
Applies to
.NET 9 和其他版本
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |