When I type ///
, Visual Studio shows me some parameters like this:
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
What is the difference between //
and ///
in C#?
When I type ///
, Visual Studio shows me some parameters like this:
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
What is the difference between //
and ///
in C#?
There is a big difference.
First: XML comments will be shown on tooltips and auto complete. Try writing XML comments and while writing the function notice how what you wrote in XML comments pops out while you type the function.
Second: you can easily use tools to generate complete documentation.
See also the official explanation on MSDN
They're both comments that won't be compiled. When you type /// in Visual Studio, it'll generate those comments for you. You can use those XML comments as documentation.
Anything typed after the first //
are treated as a comment (not compiled code). Your IDE, which is Visual Studio, uses these special XML comments to do things like show details about a method/type/etc through Intellisense.
The // comments are normal comments while /// comments are generally called xml comments. They can be utilized to make detailed help document for you classes.
When you use ///, it will generate comments based on the function header (as you see in your example), which can then be referenced when you use the function elsewhere. For example, if I had the following:
///<summary>
///Does cool things
///</summary>
///<param name="x">A cool number</param>
//There's another for return, I don't remember the exact format:
///<return>A frigid number</return>
int function(int x)
If I were to write this somewhere else:
int a = function(b);
I can put my mouse over "function" and a little window will pop up, with a summary that it does cool things and explaining that it takes a cool number and returns a frigid one. This will also work for overloads, so you can scroll through each overload header and put different summaries/variable explanations on all of them.
Single-line comment (// ):
Example:
main()
{
cout<<"Hello world"; //'cout' is used for printing the output, it prints Hello world
}
In the above example, with the // comment, describing the use of 'cout' statement.
XML Documentation comment (///):
Example:
///<summary>
/// Example 1
/// Using <summary> rag
///</summary>
For detailed info go through below link:
C#.NET Difference between // comments, /* */ comments and /// comments