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:
Recommended Posts:
- Array.GetValue() Method in C# with Examples | Set - 1
- MathF.Sin() Method in C# with Examples
- Double.CompareTo Method in C# with Examples
- UInt16.GetHashCode Method in C# with Examples
- Int64.CompareTo Method in C# with Examples
- MathF.Truncate() Method in C# with Examples
- MathF.Exp() Method in C# with Examples
- C# | Queue<T>.TrimExcess Method with Examples
- C# | Stack<T>.TrimExcess Method with Examples
- Array.BinarySearch(Array, Object) Method with examples in C#
- C# | Char.GetHashCode() Method with Examples
- C# | Char.GetTypeCode() Method with Examples
- C# | Char.GetUnicodeCategory(String, Int32) Method with Examples
- C# | Object.GetHashCode() Method with Examples
- C# | Object.GetTypeCode() Method with Examples
- Graphics.Clear() Method in C# with Examples
- Type.GetConstructors() Method in C# with Examples
- List.FindIndex() Method in C# with Examples
- Double.Equals() Method in C# with Examples
- Decimal.GetTypeCode Method in C# with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

