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

Rule:  6@118

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