Visual Studio 中的 IntellisenseIntelliSense in Visual Studio

IntelliSense 是包含一些功能的程式碼完成輔助工具:列出成員、參數資訊、快速諮詢和自動完成文字。IntelliSense is a code-completion aid that includes a number of features: List Members, Parameter Info, Quick Info, and Complete Word. 這些功能有助於深入了解您使用的程式碼、追蹤所鍵入的參數,以及幾個按鍵即可新增屬性和方法呼叫。These features help you to learn more about the code you're using, keep track of the parameters you're typing, and add calls to properties and methods with only a few keystrokes.

IntelliSense 的許多方面是特定語言專屬的。Many aspects of IntelliSense are language-specific. 如需不同語言之 IntelliSense 的詳細資訊,請參閱另請參閱小節中所列的主題。For more information about IntelliSense for different languages, see the topics listed in the See also section.

列出成員List Members

類型 (或命名空間) 中的有效成員清單隨即在您輸入觸發字元 (例如,Managed 程式碼中的句點 (.) 或 C++ 中的 ::) 之後出現。A list of valid members from a type (or namespace) appears after you type a trigger character (for example, a period (.) in managed code or :: in C++). 如果您繼續鍵入字元,則會篩選清單,只包含以這些字元開頭的成員,或名稱內「任何」字組開頭是以這些字元開頭的成員。If you continue typing characters, the list is filtered to include only the members that begin with those characters or where the beginning of any word within the name starts with those characters. IntelliSense 也會執行「駝峰式大小寫」比對,因此您可以只鍵入成員名稱中每個駝峰式大小寫字組的第一個字母以查看相符項目。IntelliSense also performs "camel case" matching, so you can just type the first letter of each camel-cased word in the member name to see the matches.

選取項目之後,您可以按 Tab 鍵或鍵入一個空格,將它插入程式碼中。After selecting an item, you can insert it into your code by pressing Tab or by typing a space. 如果您選取項目並輸入句號,則項目出現時,後面會接著句號,並顯示另一個成員清單。If you select an item and type a period, the item appears followed by the period, which brings up another member list. 當您選取某項目時,在插入項目前,會取得項目的快速諮詢。When you select an item but before you insert it, you get Quick Info for the item.

在成員清單中,左方的圖示代表成員的類型,如命名空間、類別、函式或變數。In the member list, the icon to the left represents the type of the member, such as namespace, class, function, or variable. 如需圖示清單,請參閱類別檢視和物件瀏覽器圖示For a list of icons, see Class View and Object Browser icons. 清單可能相當長,因此您可以按 PgUpPgDn,以在清單中上下移動。The list may be quite long, so you can press PgUp and PgDn to move up or down in the list.

Visual Studio 成員清單

您可以鍵入 Ctrl+J,並選擇 [編輯] > [IntelliSense] > [列出成員],或選擇編輯器工具列上的 [列出成員] 按鈕,手動叫用 [列出成員] 功能。You can invoke the List Members feature manually by typing Ctrl+J, choosing Edit > IntelliSense > List Members, or by choosing the List Members button on the editor toolbar. 在空白行或可辨識範圍外叫用清單時,清單會顯示全域命名空間中的符號。When it is invoked on a blank line or outside a recognizable scope, the list displays symbols in the global namespace.

若要預設關閉 [列出成員] (除非明確地叫用,否則不會出現),請移至 [工具] > [選項] > [所有語言],然後取消選取 [自動列出成員]。To turn List Members off by default (so that it does not appear unless specifically invoked), go to Tools > Options > All Languages and deselect Auto list members. 如果您想要只關閉特定語言的 [列出成員],請移至該語言的 [一般] 設定。If you want to turn off List Members only for a specific language, go to the General settings for that language.

您也可以變更為建議模式,在此模式中只會將您輸入的文字插入程式碼。You can also change to suggestion mode, in which only the text you type is inserted into the code. 例如,如果您輸入不在清單中的識別碼並按 Tab 鍵,則在完成模式中,項目會取代所鍵入的識別碼。For example, if you enter an identifier that is not in the list and press Tab, in completion mode the entry would replace the typed identifier. 若要在完成模式與建議模式之間進行切換,請按 Ctrl+Alt+ 空格鍵,或選擇 [編輯] > [IntelliSense] > [切換完成模式]。To toggle between completion mode and suggestion mode, press Ctrl+Alt+Space, or choose Edit > IntelliSense > Toggle Completion Mode.

參數資訊Parameter Info

[參數資訊] 會提供方法、屬性泛型類型參數 (C# 中) 或範本 (C++ 中) 所需參數的數目、名稱和類型相關資訊。Parameter Info gives you information about the number, names, and types of parameters required by a method, attribute generic type parameter (in C#), or template (in C++).

粗體的參數表示您輸入函式時,所需的下一個參數。The parameter in bold indicates the next parameter that is required as you type the function. 對於多載函式,您可以使用向上鍵向下鍵檢視函式多載的替代參數資訊。For overloaded functions, you can use the Up and Down arrow keys to view alternative parameter information for the function overloads.

參數資訊

當您以 XML 文件註解來附註函式和參數時,這些註解將會顯示成 [參數資訊]。When you annotate functions and parameters with XML Documentation comments, the comments will display as Parameter Info. 如需詳細資訊,請參閱提供 XML 程式碼註解For more information, see Supply XML code comments.

您可以選擇 [編輯] > [IntelliSense] > [參數資訊]、按 Ctrl+Shift+空格鍵,或選擇編輯器工具列上的 [參數資訊] 按鈕,手動叫用 [參數資訊]。You can manually invoke Parameter Info by choosing Edit > IntelliSense > Parameter Info, by pressing Ctrl+Shift+Space, or by choosing the Parameter Info button on the editor toolbar.

快速諮詢Quick Info

[快速諮詢] 會顯示程式碼中任一識別項的完整宣告。Quick Info displays the complete declaration for any identifier in your code.

Visual Studio 快速諮詢

當您從 [列出成員] 方塊中選取成員時,也會出現 [快速諮詢]。When you select a member from the List Members box, Quick Info also appears.

C# 程式碼檔案中的參數資訊

您可以選擇 [編輯] > [IntelliSense] > [快速諮詢]、按 Ctrl+I,或選擇編輯器工具列上的 [快速諮詢] 按鈕,手動叫用 [快速諮詢]。You can manually invoke Quick Info by choosing Edit > IntelliSense > Quick Info, by pressing Ctrl+I, or by choosing the Quick Info button on the editor toolbar.

如果函式是多載函式,IntelliSense 可能不會顯示所有多載形式的資訊。If a function is overloaded, IntelliSense may not display information for all forms of the overload.

您可以導覽至 [工具] > [選項] > [文字編輯器] > [C/C++] > [進階],然後將 [自動快速諮詢] 設定為 false,以關閉 C++ 程式碼的 [快速諮詢]。You can turn Quick Info off for C++ code by navigating to Tools > Options > Text Editor > C/C++ > Advanced, and setting Auto Quick Info to false.

自動完成文字Complete Word

在您輸入足夠的字元可清楚識別詞彙之後,[自動完成文字] 就會輸入變數、命令或函式名稱的其餘部分。Complete Word completes the rest of a variable, command, or function name after you have entered enough characters to disambiguate the term. 您可以選擇 [編輯] > [IntelliSense] > [自動完成文字]、按 Ctrl+空格鍵,或選擇編輯器工具列上的 [自動完成文字] 按鈕,叫用 [自動完成文字]。You can invoke Complete Word by choosing Edit > IntelliSense > Complete Word, by pressing Ctrl+Space, or by choosing the Complete Word button on the editor toolbar.

IntelliSense 選項IntelliSense options

IntelliSense 選項預設為開啟。IntelliSense options are on by default. 若要關閉它們,請選擇 [工具] > [選項] > [文字編輯器],然後取消選取 [參數資訊] 或 [自動列出成員] (如果您不想要列出成員功能)。To turn them off, choose Tools > Options > Text Editor and deselect Parameter information or Auto list members if you do not want the List Members feature.

IntelliSense 圖示IntelliSense icons

IntelliSense 中的圖示可以搭配圖示修飾詞來傳達其他意義。The icons in IntelliSense can convey additional meaning with icon modifiers. 這些是在物件圖示頂端的階層式星形、心形和鎖定圖示,可分別傳達受保護、內部或私人等意義。These are stars, hearts, and locks layered on top of the object's icon that convey protected, internal, or private, respectively.

圖示Icon 協助工具Accessibility 描述Description
公用圖示修飾詞 公用類別Public class 未限制存取。Access is not restricted.
受保護圖示修飾詞 受保護的類別Protected class 存取限於包含類別或衍生自包含類別的類型。Access is limited to the containing class or types derived from the containing class.
受保護內部圖示修飾詞 受保護內部類別Protected internal class 存取限於目前組件或衍生自包含類別的類型。Access is limited to the current assembly or types derived from the containing class.
內部圖示修飾詞 內部類別Internal class 存取限於目前組件。Access is limited to the current assembly.
私人圖示修飾詞 私人類別Private class 存取限於目前組件內包含類別或衍生自包含類別的類型。Access is limited to the containing class or types derived from the containing class within the current assembly. (自 C# 7.2 起可用。)(Available since C# 7.2.)

針對 IntelliSense 進行疑難排解Troubleshoot IntelliSense

IntelliSense 選項在某些情況下可能不會依照您的預期運作。The IntelliSense options may not work as you expect in certain cases.

游標位於程式碼錯誤下方。The cursor is below a code error. 如果游標上方的程式碼有不完整的函式或其他錯誤,您可能會無法使用 IntelliSense,因為 IntelliSense 可能無法剖析程式碼項目。You might not be able to use IntelliSense if an incomplete function or other error exists in the code above the cursor because IntelliSense might not be able to parse the code elements. 您可以註解適用的程式碼來解決這個問題。You can resolve this problem by commenting out the applicable code.

游標位於程式碼註解內。The cursor is in a code comment. 如果游標位於原始程式檔的註解中,則無法使用 IntelliSense。You can't use IntelliSense if the cursor is in a comment in your source file.

游標位於字串常值中。The cursor is in a string literal. 如果游標如下列範例所示位於用引號括住的字串常值中,則無法使用 IntelliSense:You can't use IntelliSense if the cursor is in the quotation marks around a string literal, as in the following example:

MessageBox( hWnd, "String literal|")

會關閉自動選項。The automatic options are turned off. IntelliSense 預設會自動運作,但您可將其停用。By default, IntelliSense works automatically, but you can disable it. 即使停用自動陳述式完成,還是可以叫用 IntelliSense 功能。Even if automatic statement completion is disabled, you can invoke an IntelliSense feature.

請參閱See also