SByte.Equals Method in C# with Examples
SByte.Equals Method is used to get a value which indicates whether the current instance is equal to a specified object or SByte or not. There are 2 methods in the overload list of this method as follows:
- Equals(SByte) Method
- Equals(Object) Method
SByte.Equals(SByte) Method
This method is used to return a value indicating whether the current instance is equal to a specified SByte value or not.
Syntax: public bool Equals (sbyte obj);
Here, it takes a SByte value to compare to the current instance.
Return Value: This method returns true if obj has the same value as this instance otherwise, false.
Below programs illustrate the use of SByte.Equals(SByte) Method:
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
sbyte value1 = 42;
sbyte value2 = 23;
bool status = value1.Equals(value2);
if (status)
Console.WriteLine( "{0} is equal to {1}" ,
value1, value2);
else
Console.WriteLine( "{0} is not equal to {1}" ,
value1, value2);
}
}
|
Output:
42 is not equal to 23
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
get (78, 58);
get (45, 45);
get (10, 20);
get (SByte.MaxValue, SByte.MinValue);
}
public static void get ( sbyte value1,
sbyte value2)
{
bool status = value1.Equals(value2);
if (status)
Console.WriteLine( "{0} is equal to {1}" ,
value1, value2);
else
Console.WriteLine( "{0} is not equal to {1}" ,
value1, value2);
}
}
|
Output:
78 is not equal to 58
45 is equal to 45
10 is not equal to 20
127 is not equal to -128
SByte.Equals(Object) Method
This method is used to returns a value indicating whether the current instance is equal to a specified object or not.
Syntax: public override bool Equals (object obj);
Here, it takes an object to compare with the current instance.
Return Value: This method returns true if obj is an instance of SByte and equals the value of this instance otherwise, false.
Below programs illustrate the use of the above-discussed method:
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
sbyte value1 = 10;
object value2 = 1 / 47;
bool status = value1.Equals(value2);
if (status)
Console.WriteLine( "{0} is equal to {1}" ,
value1, value2);
else
Console.WriteLine( "{0} is not equal to {1}" ,
value1, value2);
}
}
|
Output:
10 is not equal to 0
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
get (112, 85);
get (124, 154);
get (87, 87);
get (54, 76);
}
public static void get ( sbyte value1,
object value2)
{
bool status = value1.Equals(value2);
if (status)
Console.WriteLine( "{0} is equal to {1}" ,
value1, value2);
else
Console.WriteLine( "{0} is not equal to {1}" ,
value1, value2);
}
}
|
Output:
112 is not equal to 85
124 is not equal to 154
87 is not equal to 87
54 is not equal to 76
Reference:
Last Updated :
01 May, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...