TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Rule:  12@105

Synopsis:Use the evaluation order of && (and operator) and || (or operator) to increase performance
Language:C#
Severity Level:7
Category:Performance


Description:
C# evaluates && and || from left to right and not all arguments need to be evaluated (see below).
Use this to put expensive evaluation arguments, such as method calls with an expensive calculation, as the last argument to be evaluated.

Example &&:
Consider: if (MethodA() && MethodB()) { "do something"; }
=> if MethodA returns FALSE, MethodB is never called. Use MethodB for expensive evaluation arguments.

Example ||:
Consider: if (MethodA() || MethodB()) { "do something"; }
=> if MethodA returns TRUE, MethodB is never called. Use MethodB for expensive evaluation arguments.