注释用来对编写的代码进行说明,包括功能说明以及实现说明,这样可以大大的提高程序的可读性,另外规范的注释还可以通过工具来生成相应的API文档,C#的注释规范有以下几种:
类注释
例:
/// <summary>
/// This is a Entity Class for Post.
/// </summary>
public class Post
属性及方法注释:
/// <summary>
/// Get post with id
/// </summary>
/// <param name="id">post's identity</param>
/// <returns>post instance</returns>
public Post GetPostById(int id)
代码单行注释:
//this is a single line comment
代码多行注释:
/*
this is comment1
this is comment2
*/