註解Comments

對程式碼進行偵錯或實驗時,暫時或長期註解程式碼區塊可能很有用。When debugging or experimenting with code, it can be useful to comment blocks of code either temporarily or long term.

若要將整個程式碼區塊標記為註解:To comment out an entire block of code:

  • 選取程式碼,然後從操作功能表選取 [切換行註解]****Select the code and select Toggle Line Comment(s) from the context menu

OROR

  • 在選取的程式碼上使用 cmd + / 按鍵繫結關係。Use the cmd + / keybinding on the selected code.

這些方法可用來註解和取消註解程式碼區段。These methods can be used to comment and uncomment sections of code. 在 C# 檔案中,可以新增其他行註解層級,這可讓您註解和取消註解程式碼區域,同時仍保留實際註解:In C# files, additional levels of line comments can be added, which allows regions of codes to be commented and uncommented, while still preserving actual comments:

多層級註解

對於未來可能會與程式碼進行互動的開發人員,註解也可用來記錄程式碼。Comments are also useful for documenting code for future developers that may interact with it. 這些通常是以多行註解的形式進行,而多行註解則使用下列方式新增在每個語言中:These are usually done in the form of multi-line comments, which are added in the following way in each language:

C#C#

/*
 This is a multi-line
 comment in C#
*/

F#F#

(*
 This is a multi-line
  comment in F#
*)

另請參閱See also