سؤال

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.

http://s2.postimg.org/7synvskzt/Untitled.png

Second: you can easily use tools to generate complete documentation.

See also the official explanation on MSDN

نصائح أخرى

The // comments are normal comments while /// comments are generally called xml comments. They can be utilized to make detailed help document for you classes.

http://msdn.microsoft.com/en-us/library/b2s063f7.aspx

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.

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.

  1. Single-line comment (// ):

    • It can start with ' // '
    • It is a 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.

  1. XML Documentation comment (///):

    • It is used for XML documentation.
    • It provides information about code elements such as functions, fields and variables.

Example:

///<summary>
///   Example 1
///   Using <summary> rag
///</summary>

For detailed info go through below link:

C#.NET Difference between // comments, /* */ comments and /// comments

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top