How to: Creating Code Snippets for Visual Studio 2005/2008

Code Snippets was one of my favorite "new features" in Visual Studio 2005 and has continued to be in Visual Studio 2008.  If you've never used them, what they are (simple explanation) is a macro-capability built into the Visual Studio IDE.  They allow you to type single/multiple key strokes to define blocks of code.  So imagine: If I want to open a database connection, adapter, create a dataset, and fill it.  I could type the 5+ lines of code each time I have to do this (which is often) or I could just type something like "DataSetCode" and hit the enter button, and all of the code that I would normally hand write each time, would show up in the IDE (like a Macro).  It even has the ability to prompt me for pieces like the dataset name, connection string pieces, etc., that might vary each time I write my code.

Great feature!  There are some already built in to Visual Studio, others that you can download. 

If you want to learn how to build your own, check these links out (taken from this MSDN article)

BTW, if you don't like hand writing XML, then you might want to download this free Code Snippet Editor called: "Snippy": Click here to access the download

~ Robert Shelton


Technorati Tags: Visual Studio