Here's something I've seen several times that can lead to bugs. C# has two logical-and operators: & and &&. If you come from a C++ background, it's entirely natural to use the && operator. But there is a difference between the two operators: the && operator is a short-circuit operator.
- The & operator always evaluates both the left and right side expressions
- The && operator always evaluates the left side expression, but only evaluates the right side if the left side was true
This means with the && operator, both expressions might not be evaluated. To get the most efficient use of the && operator, you should put the key expression that is most likely to be false on the left hand side.