Skip to content

StringBuilder Has Different Equals Implementations #41230

Description

@taoyouh

Description

StringBuilder has two different versions of Equals. Equals(object) uses the version defined in class Object, while Equals(StringBuilder) uses the in-class implementation. These two different behaviors are confusing.

Considering these code. The different results are confusing.

StringBuilder a = new StringBuilder();
StringBuilder b = new StringBuilder();
object c = b;
a.Append("abc");
b.Append("abc");
Console.WriteLine(a.Equals(b)); // True
Console.WriteLine(a.Equals(c)); // False

Configuration

OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.301\

.NET Core SDK:
Version: 3.1.301
Commit: 7feb845744

Regression?

Not noticed.

Other information

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.RuntimedocumentationDocumentation bug or enhancement, does not impact product or test codehelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions