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:
// C# program to demonstrate the // SByte.Equals(SByte) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring and initializing value1 sbyte value1 = 42; // Declaring and initializing value2 sbyte value2 = 23; // using Equals(SByte) method bool status = value1.Equals(value2); // checking the status if (status) Console.WriteLine( "{0} is equal to {1}" , value1, value2); else Console.WriteLine( "{0} is not equal to {1}" , value1, value2); } } |
42 is not equal to 23
Example 2:
// C# program to demonstrate the // SByte.Equals(SByte) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // calling get() method get (78, 58); get (45, 45); get (10, 20); get (SByte.MaxValue, SByte.MinValue); } // defining get() method public static void get ( sbyte value1, sbyte value2) { // using Equals(SByte) method bool status = value1.Equals(value2); // checking the status if (status) Console.WriteLine( "{0} is equal to {1}" , value1, value2); else Console.WriteLine( "{0} is not equal to {1}" , value1, value2); } } |
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:
// C# program to demonstrate the // SByte.Equals(Object) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring and initializing value1 sbyte value1 = 10; // Declaring and initializing value2 object value2 = 1 / 47; // using Equals(object) method bool status = value1.Equals(value2); // checking the status if (status) Console.WriteLine( "{0} is equal to {1}" , value1, value2); else Console.WriteLine( "{0} is not equal to {1}" , value1, value2); } } |
10 is not equal to 0
Example 2:
// C# program to demonstrate the // SByte.Equals(Object) Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // calling get() method get (112, 85); get (124, 154); get (87, 87); get (54, 76); } // defining get() method public static void get ( sbyte value1, object value2) { // compare both SByte value // using Equals(object) method bool status = value1.Equals(value2); // checking the status if (status) Console.WriteLine( "{0} is equal to {1}" , value1, value2); else Console.WriteLine( "{0} is not equal to {1}" , value1, value2); } } |
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:
- https://docs.microsoft.com/en-us/dotnet/api/system.sbyte.equals?view=netcore-2.1