{}和//之间的区别?

Aid*_*inn 6 delphi delphi-7

是否{}//两者都根据大小添加注释?

抱歉这个愚蠢的问题,但是当我尝试google"{} // Delphi"时,我会获得Delphi.com和Wikipidia的链接以获取随机信息.

Too*_*the 17

有三种方法可以为delphi源文件添加注释:

{ This can be a single line comment }

{   but it can also span multiple lines
}

// Single line comment
Run Code Online (Sandbox Code Playgroud)

单行注释在行尾结束.其他评论有自己的结局.

(* This also can be a single comment *)

(* And it also can span multiple lines
*)

{ Can be used to comment out code containing a (* comment *)
  // Or one of those 
}
(* Can be used to coment out code containing a { comment } 
   // Or one of those 
 *)

// And this can contain the (* Single *) version of the { other } comments.
Run Code Online (Sandbox Code Playgroud)

没有真正的区别.但有些人保留一种评论方式(临时)注释掉代码.因为您不能嵌套相同的类型,但您可以嵌套不同的类型.

Trivia,(**)评论包含在支持(真实)没有{和}的旧键盘中.您也可以使用(..)作为[].

  • {}也用于编译器指令.通常(**)用于注释掉包含{}注释的部分,因为它们的优先级高于{}. (8认同)
  • 对于多行注释,`{}`或`(**)`不限** (5认同)

Sir*_*ufo 13

首先要看的是文档.

DELPHI:基本句法元素 - 注释和编译器指令


评论和编译器指令

编译器忽略注释,除非它们用作分隔符(分隔相邻的标记)或编译器指令.

有几种方法可以构建注释:

{ Text between left and right braces is a comment. }
(* Text between left-parenthesis-plus-asterisk and an 
 asterisk-plus-right-parenthesis is also a comment *)
// Text between double-slash and end of line is a comment.
Run Code Online (Sandbox Code Playgroud)

相似的评论不能嵌套.例如,(*{}*)将.后一种形式对于注释掉也包含注释的代码段很有用.以下是有关如何以及何时使用这三种注释字符的一些建议:使用double-slash(//)来注释开发期间进行的临时更改.您可以使用代码编辑器的方便的CTRL + /(斜杠)机制在您工作时快速插入双斜杠注释字符.使用括号星号(*...*)来表示开发注释以及注释掉包含其他注释的代码块.此注释字符允许编译器不考虑多行源,包括其他类型的注释.使用大括号({})作为您希望保留在代码中的源代码文档.$在打开后立即包含美元符号()的注释,{或者(*是编译器指令.例如,

{$WARNINGS OFF}
Run Code Online (Sandbox Code Playgroud)

告诉编译器不要生成警告消息.


例子

// single line comment

WriteLn( { inline comment } 'hello' );

{ multi
  line
  comment }
Run Code Online (Sandbox Code Playgroud)


小智 5

如果我错了,请纠正我,但我认为这可能对您有所帮助:

//This is a single line comment.

{
Multiple line
comment.
}

(*
This too is a
multiple line comment.
*)
Run Code Online (Sandbox Code Playgroud)