I stumbled upon this while doing a review and the author is not available:
int n = Convert.ToInt32(text);
if (((n > 0) || (n < 0)) || (n == 0))
{
return 1;
}
The code in general looks solid and it’s hard for me to believe that the only purpose of this snippet is to confuse reviewers, but I don’t see a way for this condition to fail. Am I missing something?
This may be a remnant of a nullable type. See here at msdn for an explanation, but basically if your code was originally this:
Then this could possibly fall through. Each of the statements above would be false, as n could be
nullfrom the function, assuming it returned null on a bad input, and the code supported nullable types.Unlikely, but when looking at “maintained code” anything is possible. But as written, it MUST return 1 (or throw an exception, as mentioned by others in this thread).