当前位置:网站首页>C# 注释语法
C# 注释语法
2022-08-02 03:27:00 【__Benco】
/// <summary>
/// "这里写内容,这个方法干什么的"
/// </summary>
/// <param name="sender">"是方法的名字"</param>
/// <returns>(是返回值~ 例如返回一个int等)</returns>
注释语法
为了使用C#提供的XML注释功能,你的注释应该使用特殊的注释语法“///”开头。在“///”之后,你可以使用预先定义的标签注释你的代码,也可以插入你自己定义的标签。你定制的标签将会在随后加入到生成的注释文档中。
预定义的标签 用处
<c> 将说明中的文本标记为代码
<code> 提供了一种将多行指示为代码的方法
<example> 指定使用方法或其他库成员的示例
<exception> 允许你指定可能发生的异常类
<include> 允许你引用描述源代码中类型和成员的另一文件中的注释,使用 XML XPath 语法来描述你的源代码中的类型和成员。
<list> 向XML注释文档中插入一个列表
<para> 向XML注释文档中插入一个段落
<param> 描述一个参数
<paramref> 提供了一种指示一个词为参数的方法
<permission> 允许你将成员的访问许可加入到文档中
<remarks> 用于添加有关某个类型的信息
<returns> 描述返回值
<see> 指定链接
<seealso> 指定希望在“请参见”一节中出现的文本
<summary> 类型或类型成员的通用描述
<value> 描述属性
例子
下面的例子为我们常见的HelloWorld控制台应用程序添加注释:
using System;
namespace HelloWorld
{
/// <summary>
/// Sample Hello World in C#
/// </summary>
public class HelloWorld
{
/// <summary>
/// Console Application Entry Point
/// <param name="args">Command Line Arguments</param>
/// <returns>Status code of 0 on successful run</returns>
/// </summary>
public static int Main(string[] args)
{
System.Console.WriteLine("HelloWorld");
string name = System.Console.ReadLine();
return(0);
}
}
}
为生成XML注释文档,我们在调用csc编译源代码时使用/doc选项:
csc /doc:HelloWorld.xml helloworld.cs
生成的结果文档如下:
<?xml version="1.0"?>
<doc>
<assembly>
<name>XMlComment</name>
</assembly>
<members>
<member name="T:HelloWorld.HelloWorld">
<summary>
Sample Hello World in C#
</summary>
</member>
<member name="M:HelloWorld.HelloWorld.Main(System.String[])">
<summary>
Console Application Entry Point
<param name="args">Command Line Arguments</param>
<returns>Status code of 0 on successful run</returns>
</summary>
</member>
</members>
</doc>
HTML页面
你可能会问自己:我应该如何才能得到具有良好格式的HTML页面呢?很简单,你可以编写自己的XSL来转换生成的XML注释文档,或者使用Visual Studio.NET开发工具。通过使用VS.NET的【工具】菜单中的【生成注释web页】,你可以得到一系列详细说明你的项目或解决方案的HTML页面。下面就是通过VS.NET生成的注释helloWorld程序的HTML页面快照:
边栏推荐
- kotlin语法总结(二)
- 面试知识点整理:Skia 架构的场景渲染
- 不懂“赚钱逻辑”,你永远都是社会最底层(广告电商)
- Command Execution Vulnerability
- Go Build报错汇总(持续更新)
- Windows下MySQL数据库报“ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:8000‘ (10061)”错误解决
- 考(重点理解哪些属于其他货币资金)、其他货币资金的内容、其他货币资金的账务处理(银行汇票存款、银行本票存款、信用卡存款、信用证保证金存款、存出投资款、外埠存款)
- SGDP(1)——猜数字游戏
- 文件上传漏洞
- Android-Kotlin anko库实现优雅跳转
猜你喜欢
随机推荐
The CTF introduction of PHP file contains
Laravel 的关联模型 及其 预加载多个关联 with使用方法
The learning path of a network security mouse - the basic use of nmap
CSRF (Cross Site Request Forgery)
laravel-admin 列表图片点击放大
By figure, a (complete code at the end)
cmake安装到指定目录
Solve the problem that the 5+APP real machine test cannot access the background (same local area network)
xxe of CTF
Cookie is used to collect the admin privileges CTF foundation problem
Flutter入门之网络请求篇
How to log in to Alibaba Cloud server using the admin account
Laravel 登录,中间件和路由分组
Pycharm packages the project as an exe file
库存现金、现金管理制度、现金的账务处理、银行存款、银行存款的账务处理、银行存款的核对
redis未授权访问(4-unacc)
同态加密:CKKS原理之旋转(Rotation)
The CTF introductory notes of SQL injection
Debian 12 Bookworm 尝鲜记
记账凭证的种类、记账凭证的基本内容、记账凭证的填制要求、记账凭证的审核








