Total .NET Analyzer Rule Documentation |
|
Review empty If statements.
Remarks
If statements evaluate a given expression, and perform a different action based on the result. By having no code in a If statement, you are not firing an action the expression evaluates to a specific result.
This programming technique is valid in some cases, such as when you want to "ignore" a certain expression result. For instance, the following code ignores the value of 0:
' VB
If numerator = 0 Then
' Do nothing
Else
Return numerator / denominator
End If
//C#
if(denominator == 0)
{
// Do nothing
}
else
{
return numerator/denominator;
}
You should, however, review any empty If statements in your code to determine whether an action is needed for the expression result. Empty If statements may represent unfinished work or commented out code that you actually need.
Resolution
If you have an empty If statement, you are effectively ignoring the expression result. You should examine all empty If statements to determine whether this is in fact appropriate, or whether some action is needed.
See Also
If Statements (VB)
If Statements (C#)