LDomagala
LDomagala

Reputation: 2202

What is the difference between // and /// in Visual Studio?

Stylecop is telling me to use /// instead of // when I´m commenting. What is the semantic difference for those two and when should I use which one?

Upvotes: 5

Views: 640

Answers (4)

Codingday
Codingday

Reputation: 855

There is no semantic difference, it is just a style of coding or commenting. .NET happens to choose that for comments. It is generally helpful to follow these rules for the automatic code documentation tools like sandcastle.

For instance doxygen has a completely different commenting style for C++ code. So it is mainly for consistency and standards

Upvotes: 1

Fritz H
Fritz H

Reputation: 3569

// denotes your own personal comments, where /// denote comments that can contain special data, e.g. markup for interpretation by Visual Studio - like:

/// <summary>
/// This class does something.
/// </summary>
class Bob {
    ...
}

This will tell Visual Studio the summary of the Bob class, and that will then show up in your code completion box.

Upvotes: 18

MrTelly
MrTelly

Reputation: 14875

The triple slash gives you an automatically generated template with parameters and other features automatically there for you

/// <summary>
///  Here is your comment
/// </summary>
/// <param name="sender">parameter generated automatically</param>
/// <param name="e">as above</param>
void BindableCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)

This approach means that a tool such as NDoc can then trawl your source to create documentation files automagically. Double slash just doesn't cut it ....

Upvotes: 1

LDomagala
LDomagala

Reputation: 2202

Found it myself while going through further Stylecop rules:

Use // when commentin

Use /// when documenting for XML documentation headers

Upvotes: 5

Related Questions