I have the following lines of code, where an if statement compares two strings:

string strFound = @"Testing";
string strTest = @"Testing";
if (strFound.Equals(strTest))
++iCount; // This line executes when strFound == strTest as expected
if (!(strFound.Equals(strTest)));
++iCount;// Surprisingly this line always executes even when strFound == strTest
if (strFound != strTest)
    ++iCount; // This line always executes even when strFound == strTest

I'm stepping through this in debug (VS 2012, .net 4.5) and watching the two string variables. They absolutely are equivalent, BUT for some reason the boolean logic is failing. Anyone have an idea why? Is there something silly I'm missing?

5 Years
Discussion Span
Last Post by JOSheaIV

Oh my, it's late at night! I just realized I had ';' at the end of the line of my if statement. Well, that was silly. Wish I could delete this thread.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.