C# | Byte.Equals(Byte) Method
Last Updated :
07 Feb, 2023
This method is used to return a value indicating whether this instance and a specified Byte object represent the same value.
Syntax:
public bool Equals (byte obj);
Here, obj is a byte object to compare to this instance.
Return Value: This method returns true if obj is equal to this instance otherwise, it returns false.
Below programs illustrate the use of Byte.Equals(Byte) Method:
Example 1:
CSHARP
using System;
class GFG {
public static void Main()
{
byte val1, val2;
val1 = 12;
val2 = 13;
bool i = val2.Equals(val1);
if (i)
Console.Write( "val2 is equal to val1" );
else
Console.Write( "val2 is not equal to val1" );
}
}
|
Output:
val2 is not equal to val1
Example 2:
CSHARP
using System;
class GFG {
public static void Main()
{
check(( byte )10, ( byte )20);
check(( byte )30, ( byte )20);
check(( byte )10, ( byte )10);
check(( byte )5, ( byte )7);
check(( byte )40, ( byte )50);
check(( byte )1, ( byte )1);
}
public static void check( byte v1, byte v2)
{
bool i = v1.Equals(v2);
if (i)
Console.WriteLine(v1 + " is equal to " + v2);
else
Console.WriteLine(v1 + " is not equal to " + v2);
}
}
|
Output:
10 is not equal to 20
30 is not equal to 20
10 is equal to 10
5 is not equal to 7
40 is not equal to 50
1 is equal to 1
Reference:
Share your thoughts in the comments
Please Login to comment...