Navigation:  StyleCop 4.3 > StyleCop 4.3 Rules > Layout Rules >

SA1501: StatementMustNotBeOnASingleLine

Previous pageReturn to chapter overviewNext page
StyleCop 4.3

Send comments on this topic.

SA1501: StatementMustNotBeOnASingleLine

Glossary Item Box

TypeName
StatementMustNotBeOnASingleLine

CheckId

SA1501

Category

Layout Rules

 

Cause

A C# statement containing opening and closing curly brackets is written completely on a single line.

Rule Description

A violation of this rule occurs when a statement that is wrapped in opening and closing curly brackets is written on a single line. For example:

  public object Method()

   {

      lock (this) { return this.value; }

   }

 

When StyleCop checks this code, a violation of this rule will occur because the entire lock statement is written on one line. The statement should be written across multiple lines, with the opening and closing curly brackets each on their own line, as follows:

  public object Method()

   {

      lock (this)

       {

          return this.value;

       }

   }

 

 

How to Fix Violations

To fix a violation of this rule, rewrite the statement so that it expands across multiple lines.

 


© Microsoft Corporation. All Rights Reserved.