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');
Call
What 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
Parameter
Description
obj / c1, c2
The character(s) to compare.
Return Value
Return Value
Description
true
Both characters have the same code unit.
false
They 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'));
}
}
Output
True
False
How It Works
Exact match. Uppercase A matches uppercase A.
Case matters. Lowercase a is a different code unit.
Boolean result. Print True/False directly from Equals.
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'));
}
}
Output
True
False
How It Works
Static call. Pass both sides into Char.Equals.
Matching digits. Both sevens compare equal.
Mismatch. Eight is a different character.
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);
}
}
Output
a count: 3
How It Works
Walk the string. Each element is a char.
Equals as filter. Increment only on exact matches.
Three hits. Positions of a in banana add up to 3.
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.