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
using System;
class GFG {
public static void Main()
{
check( true , true );
check( true , false );
check( false , true );
check( false , false );
}
public static void check( bool input1, bool input2)
{
bool val;
val = input1.Equals(input2);
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
using System;
class GFG {
public static void Main()
{
bool input1, input2;
input1 = true ;
input2 = false ;
bool val = input1.Equals(input2);
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:
Last Updated :
01 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...