Export (0) Print
Expand All

How to: Use Code Snippets (C#)

The following procedures describe how to use code snippets. Code snippets are available in two ways: through the snippet’s shortcut or through the Insert Code Snippet menu.

To use code snippets through the Insert Code Snippet Menu

  1. In the Visual Studio integrated development environment (IDE), open the file that you want to edit.

  2. In the Code Editor, put the cursor where you want to insert the code snippet.

  3. Launch the Insert Code Snippet menu in one of three ways:

    1. Press CTRL+K, CTRL+X.

    2. On the Edit menu, point to IntelliSense, and then click Insert Snippet.

    3. Right-click the mouse and then select the Insert Snippet command on the shortcut menu.

  4. Select the code snippet from the code snippet inserter and then press TAB or ENTER.

    Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.

To use code snippets through the snippet’s shortcut

  1. In the Visual Studio IDE, open the file that you intend to change.

  2. In the Code Editor, put the cursor where you want to insert the code snippet.

  3. Type the shortcut for the code snippet that you want to add to your code.

    OR –

    Press CTRL+SPACE to view the completion list and then select the snippet shortcut from the list.

  4. Press TAB, TAB to invoke the code snippet.

NoteNote:

This procedure can only invoke snippets that have non-null Shortcut Element (IntelliSense Code Snippets). To view a snippet's shortcut element in the Code Snippets Manager, click Code Snippets Manager on the Tools menu.

Community Additions

ADD
Show:
© 2014 Microsoft