The first line is true, the second is false. htmlOut and s2 are StringWriter objects.
bool b = s2.ToString() == htmlOut.ToString(); ret = htmlOut.Equals(s2);
I was expecting true to be b, but why is ret false?
StringWriter does not override object.Equals.
htmlOut.Equals(s2);
is equivalent to:
object.ReferenceEquals(htmlOut, s2);
StringWriteruses internal StringBuilderfor recording. StringWriter.ToString()returns a string constructed with StringBuilder.
StringWriter
StringBuilder
StringWriter.ToString()
StringWriterdoes not cancel object.Equals(), therefore it StringWriter.Equals()compares if both objects are the same link, and not if their string representations are equal.
object.Equals()
StringWriter.Equals()
Equals . htmlOut Equals ?
, , , , , , .
htmlOut.ToString().Equals(s2.ToString());
it will return true
Source: https://habr.com/ru/post/1713563/More articles:OpenOffice :: OODoc stylize text in paragraph - perl.NET Programming - Can I Access C-Sharp Project Members from My VB.NET Project? - c #Шаг отладчика Visual Studio в скомпилированный источник - debuggingWhy doesn't Cache :: clear () clear my (view) cache? (CakePHP) - cachinghttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1713562/subversion-how-do-i-commit-i-updated-one-of-my-project-directories-to-a-previous-revision&usg=ALkJrhiGlQDiigmAPiCL1Lc7kSgIhzlGYwMethod overloading - c #Закрытие сеанса Wicket - javahow to reset response headers in ASP.Net - c #How to read and study the T_SQL execution plan? - sql-serverUsing Maven in the Hibernate Tutorial - maven-2All Articles