SSW Foursquare

Do you know how to avoid problems in if-statements?

Last updated by Brady Stroud [SSW] about 1 month ago.See history

Try to avoid problems in if-statements without curly brackets and just one statement which is written one line below the if-statement. Use just one line for such if-statements. If you want to add more statements later on and you could forget to add the curly brackets which may cause problems later on.

if (ProductName == null) ProductName = string.Empty; if (ProductVersion == null)
 ProductVersion = string.Empty; if (StackTrace == null) StackTrace = string.Empty;

Figure: Bad Example

if (ProductName == null)
{
 ProductName = string.Empty;
}
if (ProductVersion == null)
{
 ProductVersion = string.Empty;
}
if (StackTrace == null)
{
 StackTrace = string.Empty;
}

Figure: Good Example

Adam Cogan
We open source. Powered by GitHub