views:

252

answers:

5

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?

+4  A: 

Found it myself while going through further Stylecop rules:

Use // when commentin

Use /// when documenting for XML documentation headers

LDomagala
+15  A: 

// 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.

Fritz H
A: 

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 ....

MrTelly
+1  A: 

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

Can Erten
A: 

Comments written in /// show up in intellisense while the others with // don't

Hasan Khan