Visual Studio Code Snippet

April 14, 2010 1 comment

 

What is the Code Snippet?

Code snippets provide faster code generation with developer’s input options. Visual Studio supports various code snippets for C#,VB,XML and so on.

Checking Code Snippets in Visual Studio

You can check installed snippets in Visual Studio easily. Open Visual Studio > Tools > Code Snippets Manager.

001.location of code snippets manager

Navigate to the installed snippets in the Snippets Manager. You can see the information and locations of many snippets.

002.code snippets manager

These are installed snippets on my Visual Studio 2008.

003.installed snippets

Selecting C# snippets in the Visual Studio.

OK. Let us start to use a snippet for practice. We will use the “prob” snippet to generate private property with getter and setter. In the C# editor, type the start characters of “prop” and you can see the list of similar snippets. After selecting, press the TAB key twice.

004.typing snippet shortcut

The “int” and “MyProperty” strings with background color are the objects waiting your customizations. You can navigate objects in this snippet using TAB key.

005.navigate

Filling C# snippets.

Write some start words you want. If there are matched object type, you can see candidate list. Select and press TAB to fill.

006.value input

If you finish filling objects in the snippet, press ENTER key to exit.

007.finish