Code Snippets (C#) easy shortcuts for C# programming

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

  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.
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: