支持两种形式的注释:单行注释和带分隔符的注释。单行注释以字符 // 开头并延续到源行的结尾。带分隔符的注释以字符 /* 开头,以字符 */ 结束。带分隔符的注释可以跨多行。 comment:(注释:) single-line-comment(单行注释)delimited-comment(带分隔符的注释) single-line-comment:(单行注释:) // input-charactersopt(// 输入字符可选) input-characters:(输入字符:) input-character(输入字符)input-characters input-character(输入字符 输入字符) input-character:(输入字符:) 除换行符外的任何 Unicode 字符 new-line-character:(换行符:) 回车符 (U+000D)换行符 (U+000A)行分隔符 (U+2028)段落分隔符 (U+2029) delimited-comment:(带分隔符的注释:) /* delimited-comment-charactersopt */(/* 带分隔符的注释字符可选 */) delimited-comment-characters:(带分隔符的注释字符:) delimited-comment-character(带分隔符的注释字符)delimited-comment-characters delimited-comment-character(带分隔符的注释字符 带分隔符的注释字符) delimited-comment-character:(带分隔符的注释字符:) not-asterisk(非星号)* not-slash(* 非斜杠) not-asterisk:(非星号:) 除 * 外的任何 Unicode 字符 not-slash:(非斜杠:) 除 / 外的任何 Unicode 字符 注释不嵌套。字符序列 /* 和 */ 在 // 注释中没有任何特殊含义,字符序列 // 和 /* 在带分隔符的注释中没有任何特殊含义。 在字符和字符串文本内不处理注释。 示例/* Hello, world program This program writes "hello, world" to the console */ class Hello { static void Main() { System.Console.WriteLine("hello, world"); } } 包含一个带分隔符的注释。 示例// Hello, world program // This program writes "hello, world" to the console // class Hello // any name will do for this class { static void Main() { // this method must be named "Main" System.Console.WriteLine("hello, world"); } } 显示了若干单行注释。

评论