This rule is Obsolete | |
Synopsis: | Do not use selection statements (if, switch) instead of a simple assignment or initialization |
Language: | C# |
Severity Level: | 5 |
Category: | Control flow |
Description: |
Express your intentions directly. For example, rather than
bool pos; if (val > 0) { pos = true; } else { pos = false; } or (slightly better)
bool pos = (val > 0) ? true : false; write
bool isPositiveValue; isPositiveValue = (val > 0); // single assignment or even better
bool isPositiveValue = (val > 0); // initialization |