Navigation:  StyleCop 4.3 > StyleCop 4.3 Rules > Documentation Rules >

SA1626: SingleLineCommentsMustNotUseDocumentationStyleSlashes

Previous pageReturn to chapter overviewNext page
StyleCop 4.3

Send comments on this topic.

SA1626: SingleLineCommentsMustNotUseDocumentationStyleSlashes
Glossary Item Box
TypeName

SingleLineCommentsMustNotUseDocumentationStyleSlashes

CheckId

SA1626

Category

Documentation Rules

 

Cause

The C# code contains a single-line comment which begins with three forward slashes in a row.

Rule Description

A violation of this rule occurs when the code contains a single-line comment which begins with three slashes. Comments beginning with three slashes are reserved for Xml documentation headers. Single-line comments should begin with only two slashes. When commenting out lines of code, it is advisable to begin the comment with four slashes to differentiate it from normal comments. For example:

  /// <summary>

  /// Joins a first name and a last name together into a single string.

  /// </summary>

  /// <param name="firstName">Part of the name.</param>

  /// <param name="lastName">Part of the name.</param>

  /// <returns>The joined names.</returns>

  public string JoinNames(string firstName, string lastName)

   {

A legal comment beginning with two slashes:

      // Join the names together.

      string fullName = firstName + " " + lastName;

 

An illegal comment beginning with three slashes:

      /// Trim the name.

       fullName = fullName.Trim();

 

A line of commented-out code beginning with four slashes:

      ////fullName = asfd;

 

       return fullName;

   }

 

How to Fix Violations

To fix a violation of this rule, remove a slash from the beginning of the comment so that it begins with only two slashes.

 

 


© Microsoft Corporation. All Rights Reserved.