SSW Foursquare

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

Last updated by Brady Stroud [SSW] 7 months 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.Loving SSW Rules? Star us on GitHub. Star
Stand by... we're migrating this site to TinaCMS