Thursday, February 09, 2006

MSDN

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.

No comments: