Do you know how to avoid problems in if-statements?
25/04/2018 8:01 AM by
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)Figure: Bad Example
ProductVersion = string.Empty; if (StackTrace == null) StackTrace = string.Empty;
if (ProductName == null) Figure: Good Example
ProductName = string.Empty;
if (ProductVersion == null)
ProductVersion = string.Empty;
if (StackTrace == null)
StackTrace = string.Empty;
Do you feel this rule needs an update?