Visual Studio provides a new feature called code snippets
. You can use code snippets to type a short alias, and then expand it into a common programming construct. For example, the
for code snippet creates an empty
for loop.
Code snippets are normally used in the Code Editor by typing a short name for the alias — a code snippet shortcut — then pressing TAB. The IntelliSense menu also offers an
Insert Code Snippet menu command, providing a list of available code snippets for insertion into the Code Editor. You can activate the code snippet list by typing CTRL+K, then X.
When a field is selected, users can type a new value for the field. Pressing TAB cycles through the editable fields of the code snippet; pressing SHIFT+TAB cycles through them in reverse order. Clicking on a field places the cursor in the field, and double-clicking on a field selects it. When a field is highlighted, a tooltip might be displayed, offering a description of the field.
Pressing ENTER or ESC will cancel field editing and return the Code Editor to normal.
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
- In the Visual Studio IDE, open the file that you intend to edit.
- In the Code Editor, place the cursor where you would like to insert the code snippet.
- Type CTRL+K, CTRL+X.
- 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
- In the Visual Studio IDE, open the file that you intend to edit.
- In the Code Editor, place the cursor where you would like to insert the code snippet.
- Type the shortcut for the code snippet that you want to add to your code.
- Type TAB, TAB to invoke the code snippet.
To use code snippets through the IntelliSense Complete Word list
- In the Visual Studio IDE, open the file that you intend to edit.
- In the Code Editor, place the cursor where you would like to insert the code snippet.
- 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.
- Select the code snippet from the complete word list.
- Type TAB, TAB to invoke the code snippet.
To use code snippets through the Edit menu
- In the Visual Studio IDE, open the file that you intend to edit.
- In the Code Editor, place the cursor where you would like to insert the code snippet.
- From the Edit menu, select IntelliSense and then select the Insert Snippet command.
- 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
- In the Visual Studio IDE, open the file that you intend to edit.
- In the Code Editor, place the cursor where you would like to insert the code snippet.
- Right-click the cursor and then select the Insert Snippet command from the context menu.
- 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.
For Example
I am using this snippets in my .cs code file i simple press Control Key + K and then press X key .then you will get a screen like this .
then press Enter Key
then select the type that you want to use and finally you get the empty block of code.
0 comments: