C# Char Equals() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

In C#, Equals asks whether two char values are the same UTF-16 code unit. Instance and static overloads both exist.

For most code, the == operator is clearer. Use Equals when you need a method form (for example, with some APIs that expect a method).

This is an instance member of System.Char. You call it on a char value with a dot, such as c.Equals(...). A char holds one 16-bit UTF-16 code unit.

Syntax

Call on a char, or use the static Char.Equals helper.

C#
char a = 'A';
bool same = a.Equals('A');
bool also = Char.Equals(a, 'A');
CallWhat it does
a.Equals('A')Instance: true when values match.
Char.Equals(a, 'B')Static: compares two chars.

Equality is case-sensitive: 'A' is not equal to 'a'.

Library declarations
C#
public bool Equals(char obj);
public static bool Equals(char c1, char c2);

Parameters

ParameterDescription
obj / c1, c2The character(s) to compare.

Return Value

Return ValueDescription
trueBoth characters have the same code unit.
falseThey differ.

C# Examples

Example 1 — Match a Letter

Test whether a stored char equals 'A'.

C#
using System;

class Program {
    static void Main() {
        char c = 'A';
        Console.WriteLine(c.Equals('A'));
        Console.WriteLine(c.Equals('a'));
    }
}

How It Works

  1. Exact match. Uppercase A matches uppercase A.
  2. Case matters. Lowercase a is a different code unit.
  3. Boolean result. Print True/False directly from Equals.
  4. Same as ==. For chars, Equals and == agree on value equality.

Example 2 — Compare Two Variables

Use the static overload with two char arguments.

C#
using System;

class Program {
    static void Main() {
        char left = '7';
        char right = '7';
        Console.WriteLine(Char.Equals(left, right));
        Console.WriteLine(Char.Equals(left, '8'));
    }
}

How It Works

  1. Static call. Pass both sides into Char.Equals.
  2. Matching digits. Both sevens compare equal.
  3. Mismatch. Eight is a different character.
  4. Handy in helpers. Static form works well inside small utility methods.

Example 3 — Count Matching Chars

Count how many times a target appears in a string.

C#
using System;

class Program {
    static void Main() {
        string text = "banana";
        char target = 'a';
        int count = 0;

        foreach (char ch in text) {
            if (ch.Equals(target)) count++;
        }

        Console.WriteLine("a count: " + count);
    }
}

How It Works

  1. Walk the string. Each element is a char.
  2. Equals as filter. Increment only on exact matches.
  3. Three hits. Positions of a in banana add up to 3.
  4. Could use ==. The operator would work the same here.

Frequently Asked Questions

Yes for value equality of two chars. Prefer == for everyday code.
No. Convert case first if you need that behavior.
Yes: Char.Equals(c1, c2).
There is an object overload; prefer the char overload.
When an API expects a method, or you want a named equality call.

Next: GetHashCode()

Return a hash code for this character, useful in hash-based collections with System.Char.

GetHashCode() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful