Boolean.Equals(Object) Method in C#


The Boolean.Equals(Object) method in C# returns a value indicating whether this instance is equal to a specified object.

Syntax

Following is the syntax −

public override bool Equals (object ob);

Above, ob is an object to compare to this instance.

Example

Let us now see an example to implement the Boolean.Equals(Object) method −

using System;
public class Demo {
   public static void Main(){
      bool val1 = true;
      object val2 = 5/10;
      if (val1.Equals(val2))
         Console.WriteLine("Both are equal!");
      else
         Console.WriteLine("Both aren't equal!");
   }
}

Output

This will produce the following output −

Both aren't equal!

Updated on: 11-Nov-2019

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements