工具列 → 「工具」→ 「程式碼片段管理器」(或 Ctrl+K, Ctrl+B),可檢視/匯入/匯出片段。

預設路徑:%USERPROFILE%\Documents\Visual Studio 20xx\Code Snippets\Visual C#\My Code Snippets
每個片段為 .snippet XML 檔,核心欄位:
Shortcut:觸發關鍵字(如 if、prop)Code:CDATA 區塊內的模板內容,$variable$ 為可替換參數,$selected$、$end$ 為游標佔位Declarations/Literal:參數說明與預設值if.snippet 重命名 maction.snippet<Header>
<Title>MAction</Title>
<Shortcut>ma</Shortcut> <!-- 輸入 ma 觸發 -->
<Description>MAction using 區塊</Description>
<Author>Your Name</Author>
<SnippetTypes><SnippetType>Expansion</SnippetType></SnippetTypes>
</Header>
<Snippet>
<Declarations> <!-- 無參數可保留空或移除 --> </Declarations>
<Code Language="csharp"><![CDATA[
using (MAction action = new MAction($end$)) {
$selected$
}]]></Code>
</Snippet>

ma → 按 TabTab → 展開:using (MAction action = new MAction(│)) {
;
}
游標停留在建構函式參數位置($end$),若先選取程式碼再觸發,選取內容會填入 $selected$。

using、try-catch、INotifyPropertyChanged、Log 呼叫等)做成 2-3 字母 Shortcut。$selected$ 實現「包裹既有代碼」片段(SnippetType: SurroundsWith)。