dotnet/runtime

StringBuilder Has Different Equals Implementations

開放

#41,230 建立於 2020年8月23日

 (14 則留言) (0 個反應) (0 位負責人)C# (5,445 個分叉)batch import
area-System.Runtimedocumentationhelp wanted

倉庫指標

星標
 (17,886 顆星)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

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.

貢獻者指南