Tuesday, June 15, 2010

Code Snippets in Visual Studio 2008/2010

Another cool feature of Microsoft Visual Studio 2008/2010. Code snippets are pieces of codes that are pre-set in snippets files and has a shortcut associated with it. This feature can save you a lot of time coding.
we all build our "for" statements and "if" statements and all kind of code parts that we code repeatedly almost everyday.
VS comes with many snippets preloaded but you can add your own if you have a specific code snippets specific to you that you want to add to the library.

Here is how it looks when you start typing the shortcuts. The code snippets has their own icon (Click the Image to enlarge)::




Once you choose your snippet than click the "tab" button twice and the code will populate:





In order to see all the available snippets or add your own go to "tools" -> "Code Snippets Manager"

Click the Image to enlarge



And you will see this screen (Click the Image to enlarge):

Click the Image to enlarge



To create a code snippet of your own you will need to build the file in a n XML format and supply it with all the attributes (shortcut, code etc.).


Here is how the above "for" statement snippet file looks like (Click the Image to enlarge)::

Click the Image to enlarge

No comments:

Post a Comment