C# | Boolean.Equals(Boolean) Method
This method is used to return a value indicating whether this instance is equal to a specified Boolean object.
Syntax:
public bool Equals (bool obj);
Here, obj is a boolean value to compare to this instance.
Return Value: This method returns true if obj has the same value as this instance otherwise it returns false.
Below programs illustrate the use of Boolean.Equals(bool obj) Method:
Example 1:
CSHARP
// C# program to demonstrate// Boolean.Parse(String)// Methodusing System;class GFG { // Main Method public static void Main() { // passing different values // to the method to check check(true, true); check(true, false); check(false, true); check(false, false); } // Defining check method public static void check(bool input1, bool input2) { // declaring bool variable bool val; // getting parsed value val = input1.Equals(input2); // checking the equivalency if (val == true) Console.WriteLine("{0} is equal to {1}", input1, input2); else Console.WriteLine("{0} is not equal to {1}", input1, input2); }} |
Output:
True is equal to True True is not equal to False False is not equal to True False is equal to False
Example 2:
CSHARP
// C# program to demonstrate// Boolean.Parse(String)// Methodusing System;class GFG { // Main Method public static void Main() { // Declaring the variable // input1 and input2 bool input1, input2; // initializing the variables input1 = true; input2 = false; // checking the equality bool val = input1.Equals(input2); // checking the equivalency if (val == true) Console.WriteLine("input1 is equal to input2"); else Console.WriteLine("input1 is not equal to input2"); }} |
Output:
input1 is not equal to input2
Note: This method implements the System.IEquatable<T> interface, and performs slightly better than Equals because it does not have to convert the obj parameter to an object.
Reference:


