StringComparer.Equals Method

Definition

When overridden in a derived class, indicates whether two objects or strings are equal.

Overloads

Equals(Object, Object)

When overridden in a derived class, indicates whether two objects are equal.

Equals(String, String)

When overridden in a derived class, indicates whether two strings are equal.

Equals(Object, Object)

Source:
StringComparer.cs
Source:
StringComparer.cs
Source:
StringComparer.cs

When overridden in a derived class, indicates whether two objects are equal.

C#
public bool Equals(object? x, object? y);
C#
public bool Equals(object x, object y);

Parameters

x
Object

An object to compare to y.

y
Object

An object to compare to x.

Returns

true if x and y refer to the same object, or x and y are both the same type of object and those objects are equal, or both x and y are null; otherwise, false.

Implements

Remarks

Because the runtime does not have to unbox x or y if they are value types or attempt to downcast x or y to strings if they are reference types, the Equals(String, String) method may be slightly more efficient than the Equals(Object, Object) method.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Equals(String, String)

Source:
StringComparer.cs
Source:
StringComparer.cs
Source:
StringComparer.cs

When overridden in a derived class, indicates whether two strings are equal.

C#
public abstract bool Equals(string x, string y);
C#
public abstract bool Equals(string? x, string? y);

Parameters

x
String

A string to compare to y.

y
String

A string to compare to x.

Returns

true if x and y refer to the same object, or x and y are equal, or x and y are null; otherwise, false.

Implements

Remarks

Because the runtime does not have to unbox x or y if they are value types or attempt to downcast x or y to strings if they are reference types, the Equals(String, String) method may be slightly more efficient than the Equals(Object, Object) method.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0