C# string equality operator returns false, but I'm pretty sure it should be true... What?!

Posted by Daniel Schaffer on Stack Overflow See other posts from Stack Overflow or by Daniel Schaffer
Published on 2010-04-01T03:49:32Z Indexed on 2010/04/01 3:53 UTC
Read the original article Hit count: 221

Filed under:
|
|

I'm trying to write a unit test for a piece of code that generates a large amount of text. I've run into an issue where the "expected" and "actual" strings appear to be equal, but Assert.AreEqual throws, and both the equality operator and Equals() return false. The result of GetHashCode() is different for both values as well.

However, putting both strings into text files and comparing with DiffMerge tells me they're the same.

Additionally, using Encoding.ASCII.GetBytes() on both values and then using SequenceEquals to compare the resulting byte arrays returns true.

The values are 34KB each, so I'll hold off putting them here for now. Any ideas? I'm completely stumped.

© Stack Overflow or respective owner

Related posts about c#

Related posts about string