如何在 C# 中为方法添加 (IntelliSense) 参数注释
当我使用任何 .NET 方法时,都会有一些提示(IntelliSense)来解释这些方法及其参数。
我如何为我自己的方法实现相同的行为?
Visual Studio 是否有功能允许我添加这些内容?
When I use any .NET methods, there is a little hint (IntelliSense) which explains the methods and their parameters.
How do I achieve the same behaviour for my own methods?
Is there a Visual Studio feature which allows me to add these in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
该“功能”称为XML 注释。只需在方法之前输入 /// ,VS 就会生成一些 xml 标签。这些将用于显示工具提示以及参数信息。
我的 VS2010 调用方法 add 时的屏幕截图。如您所见,显示了 xml 注释。

the "feature" is called XML comments. Just type /// right before your methods and VS will generate some xml tags. These will be used to show the tooltip as well as parameter info aso.
Screenshot of my VS2010 when calling method add. As you can see, xml comments are shown.

是的,你可以。下面是一个示例:
要自动生成 xml 注释,只需在方法、属性、类等上方键入
///
即可。并且 这里是文档的推荐标签。您还可以使用 GhostDoc 来简化您的文档职责。Yes you can. Heres an example:
To automatically generate xml comment just type
///
above your method, property, class, etc. And here is recommended tags for documentation. Also you can use GhostDoc to simplify your documentation duty.它称为 XML 文档。您必须在方法签名上方写下以下注释:
It's called XML documentation. You have to write the following comments above your method signature:
您可以在函数中添加特殊注释(注意 3 个斜杠)这是一个简短的示例:
说明:
<强><<摘要>> 是用于解释功能的标签
<< param name="" >> 解释一个参数
<< returns >> 用于解释retunr值的标签。
当您编辑该注释时,Visual Studio 将显示更多标签。
You can do bay adding a special comment to your function (Mind the 3 slashes) Here is a short example:
Explanation:
<< summary >> Is the tag for to explain the functionality
<< param name="" >> Explains one paremter
<< returns >> The tag for the explanation of the retunr value.
There are several more tags, whoch Visual Studio will show you, when you edit that comment.
你需要这样的 xml 注释 就像
msdn 上描述的那样
http://msdn.microsoft.com/en-我们/库/b2s063f7(v=VS.100).aspx
You Need xml comments like this
Like described on msdn
http://msdn.microsoft.com/en-us/library/b2s063f7(v=VS.100).aspx
如果您在方法/属性上方按正斜杠三次,Visual Studio 将生成一个 XML 注释摘要,然后您可以使用相关信息填充该摘要。
另一个好的提示是,如果您转到项目属性,然后转到“构建”选项卡,您将看到底部有“输出”部分。如果您每次构建项目时都勾选 XML 文档文件,您的 API 的 XML 文件将与 dll 一起生成,这对于使用您的 API 的其他开发人员来说非常有用。这也意味着 Visual Studio 将对任何尚未发表评论或评论错误的公众成员发出警告。
If you press forward slash three times when above your method/property visual studio will generate an XML comments summary which you can then populate with the relevant info.
Another good tip is that if you go to project properties and then the Build tab you will see towards the bottom there is am Output section. If you tick the XML documentation file each time your project is built an XML file for your API will be generated alongside the dll which is great for other developers consuming your API. This also means that visual studio will raise warnings for any public member that is not yet commented or commented incorrectly.
是的,你可以。这是 Xml 文档请参阅此处
Yes you can. It's Xml documentation see here