Char.Equals() Method in C#


The Char.Equals() method in C# is used to return a value that indicates whether this instance is equal to a specified object or Char value.

Syntax

Following is the syntax −

public bool Equals (char ob);

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

Example

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

using System;
public class Demo {
   public static void Main(){
      char val = 'A';
      bool res;
      res = val.Equals('A');
      Console.WriteLine("Return Value = "+res);
   }
}

Output

This will produce the following output −

Return Value = True

Example

Let us now see another example −

using System;
public class Demo {
   public static void Main(){
      char val = 'H';
      bool res;
      res = val.Equals('d');
      Console.WriteLine("Return Value = "+res);
   }
}

Output

This will produce the following output −

Return Value = False

Updated on: 12-Nov-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements