Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C#
Code Snippets
 How to: Use Code Snippets

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:

Want more? Here are some additional resources on this topic:

Visual C# Application Development 
How to: Use Code Snippets (C#) 

The following procedures describe how to use code snippets. Code snippets are available in five ways: through a keyboard shortcut, through IntelliSense auto-completion, through the IntelliSense complete word list, through the Edit menu, and through the context menu.

To use code snippets through keyboard shortcut

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

  2. In the Code Editor, place the cursor where you would like to insert the code snippet.

  3. Type CTRL+K, CTRL+X.

  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 IntelliSense auto-completion

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

  2. In the Code Editor, place the cursor where you would like to insert the code snippet.

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

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

To use code snippets through the IntelliSense Complete Word list

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

  2. In the Code Editor, place the cursor where you would like to insert the code snippet.

  3. Begin typing the shortcut for the code snippet that you want to add to your code. If automatic completion is turned on, then the IntelliSense complete word list will be displayed. If it does not appear, then press CTRL+SPACE to activate it.

  4. Select the code snippet from the complete word list.

  5. Type TAB, TAB to invoke the code snippet.

To use code snippets through the Edit menu

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

  2. In the Code Editor, place the cursor where you would like to insert the code snippet.

  3. From the Edit menu, select IntelliSense and then select the Insert Snippet command.

  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 context menu

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

  2. In the Code Editor, place the cursor where you would like to insert the code snippet.

  3. Right-click the cursor and then select the Insert Snippet command from the context 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.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker