简体   繁体   English

c# 中 // 和 /// 之间的区别

[英]Difference between // and /// in c#

When I type /// , Visual Studio shows me some parameters like this:当我输入/// ,Visual Studio 会向我显示一些如下参数:

/// <summary>
/// 
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

What is the difference between // and /// in C#? C# 中的/////什么区别?

There is a big difference.有很大的不同。

First : XML comments will be shown on tooltips and auto complete .第一:XML 注释将显示在工具提示和自动完成上 Try writing XML comments and while writing the function notice how what you wrote in XML comments pops out while you type the function.尝试编写 XML 注释,并在编写函数时注意在键入函数时在 XML 注释中所写的内容如何弹出。

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

Second : you can easily use tools to generate complete documentation .第二:可以轻松地使用工具生成完整的文档

See also the official explanation on MSDN另见MSDN上的官方解释

They're both comments that won't be compiled.它们都是不会被编译的注释。 When you type /// in Visual Studio, it'll generate those comments for you.当您在 Visual Studio 中键入 /// 时,它会为您生成这些注释。 You can use those XML comments as documentation.您可以将这些 XML 注释用作文档。

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.您的 IDE(即 Visual Studio)使用这些特殊的 XML 注释来执行诸如通过 Intellisense 显示有关方法/类型/等的详细信息的操作。

The // comments are normal comments while /// comments are generally called xml comments. // 注释是普通注释,而 /// 注释通常称为 xml 注释。 They can be utilized to make detailed help document for you classes.它们可用于为您的课程制作详细的帮助文档。

http://msdn.microsoft.com/en-us/library/b2s063f7.aspx 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.这也适用于重载,因此您可以滚动浏览每个重载标题并在所有标题上放置不同的摘要/变量解释。

  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.在上面的例子中,用//注释,描述了'cout'语句的使用。

  1. XML Documentation comment (///): XML 文档注释 (///):

    • It is used for XML documentation.它用于 XML 文档。
    • 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 C#.NET // 注释、/* */ 注释和 /// 注释之间的区别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM