IntelliCode 建議IntelliCode suggestions

當您在程式碼中的多個位置進行類似的編輯時,IntelliCode 建議可協助您。IntelliCode suggestions assists you when making similar edits in multiple places in your code. 它會追蹤您在本機的編輯,並偵測重複。It tracks your edits locally, and detects repetition. 然後,它會提供在可能適用的其他地方套用這些相同的編輯。It then offers to apply those same edits in other places where they might apply. 例如,如果您沒有可套用重構的位置,IntelliCode 建議可協助您找出這些位置並加以修正。For example, if you have missed locations where a refactoring could be applied, IntelliCode suggestions helps you find those locations and fix them.

IntelliCode 知道您程式碼的語義結構。IntelliCode is aware of the semantic structure of your code. 該結構是用來偵測可以套用變更的情況,即使變數名稱不同也是一樣。That structure is used to detect situations where changes can be applied, even if variable names are different.

假設您使用 helper 函式來取代重複的溫度轉換。Suppose you are replacing a repeated temperature conversion with a helper function. IntelliCode 會偵測您所做的重複變更,並建議您在其他地方進行這項變更。IntelliCode will detect the repeated change you are making, and suggest you make that change in other places.


建議會在 Visual Studio 編輯器中顯示為快速動作Suggestions appear as Quick Actions in Visual Studio editor. IntelliCode 建議: [快速動作] 功能表選項會套用建議,並略過這類建議IntelliCode suggestions have the Quick Action menu options Apply suggestion and Ignore suggestions like this. 如果您想要使用建議的變更,請選取 [套用建議]。If you want to use the suggested change, select Apply suggestion.

IntelliCode 建議燈泡

如果您不想要使用建議的變更,請選取 [忽略此動作的建議]。If you don’t want to use the suggested change, select the Ignore suggestions like this action. 除非您重新建立,否則 IntelliCode 不會再次對您造成這種模式的干擾。IntelliCode won’t bother you about that pattern again unless you recreate it.

如果您想要查看所有建議變更的清單,請移至 [查看 > 其他 windows > IntelliCode 建議]。If you want to see the list of all suggested changes, go to View > Other windows > IntelliCode suggestions.

預覽功能Preview features

當 IntelliCode 偵測到重複的編輯時,您可能會看到燈泡。You may see a lightbulb when IntelliCode detects a repeated edit. 燈泡有一個動作,將會顯示所找到的建議清單。The lightbulb has an action which will show you a list of the suggestions found. 這會開啟 [IntelliCode 建議] 視窗,讓您可以找出並採取建議。This opens the IntelliCode suggestions window, so you can locate and act on the suggestions.

您可以在 [工具 > Options > ] [選項][IntelliCode] [一般] 索引標籤中設定此燈泡,並啟用/停用 [發現新的建議時顯示燈泡]You can configure this lightbulb at Tools > Options > IntelliCode General tab, and enable/disable "Show lightbulb when new suggestion is discovered".

IntelliCode 建議探索

停用 IntelliCode 建議Disable IntelliCode suggestions

預設會針對 Visual Studio 16.7 版和更新版本開啟建議。Suggestions is turned on by default for Visual Studio version 16.7 and above.

如果您想要將它關閉,請選擇 [工具] [ > 選項]、 [IntelliCode 一般] 索引標籤,然後將c # 建議切換為停用If you wish to turn it off, choose Tools > Options, IntelliCode General tab, and then switch C# suggestions to Disabled: