Send comments on this topic. |
|
Cause
Rule Description
A violation of this rule occurs when a single-line comment is not preceded by a blank line. For example:
public bool Enabled
{
get
{
Console.WriteLine("Getting the enabled flag.");
// Return the value of the 'enabled' field.
return this.enabled;
}
}
The code above would generate an instance of this violation, since the single-line comment is not preceded by a blank line.
An exception to this rule occurs when the single-line comment is the first item within its scope. In this case, the comment should not be preceded by a blank line. For example:
public bool Enabled
{
get
{
// Return the value of the 'enabled' field.
return this.enabled;
}
}
In the code above, the comment is the first item within its scope, and thus it should not be preceded by a blank line.
If the comment is being used to comment out a line of code, begin the comment with four forward slashes rather than two. This will cause StyleCop to ignore this violation. For example:
public bool Enabled
{
get
{
Console.WriteLine("Getting the enabled flag.");
////return false;
return this.enabled;
}
}
How to Fix Violations
© Microsoft Corporation. All Rights Reserved.