When I teach the Complete C# class here at Intertech, I do a number of live demos with the class. During that time, I try to show as many useful code snippets has possible.
Many .NET programmers are unaware of the built in code-snippets of VS 2010. Basically, a code snippet is a XML document that defines data such as the name of the code snippet, which code to dump in the editor when the snippet is activated, and any ?placeholders? in the snippet.
One thing to be aware of is that the C# and VB code editors each treat code snippet technology a tad different, so for this post, I?ll show how to work with a snippet within a C# project.
You can activate a code snippet in a few ways. If you happen to know the name of the snippet you are trying to activate, just type it by name. You?ll notice the icon for a code snippet looks a bit like a torn piece of paper (at least to me!). For example, let?s say you wish to iterate over incoming command line arguments for a Main() method of an executable. Simply type in the work ?foreach?:

Once you find the snippet, press the TAB key twice on your keyboard. The first time will autocomplete any partial typing of the snippet (ex: fore for foreach) but the second TAB will execute the code placement:

Now, keep clicking the Tab key. You will see focus will transfer to any ?placeholders? you need to fill in. Since we are iterating over a string array, we can type in string for the first placeholder, tab over the second (item is a fine enough name) and then tab to the third placeholder and substitute ?collection? with args (the name of the incoming string array). Once you are done, you can find the following:
Once you are happy with your placeholder values, press the Esc key to exit ?snippet mode? (be aware!! Once you exit snippet mode, there is no way to return! If you need to change anything, you will need to do so manually, or delete the code and start again).
Now, in the scope of the foreach loop, type in cw TAB TAB (cw is a handy code snippet for the first set of labs of the C# class, as it dumps a Console.WriteLine() call). At this point, just print out the name of the current string in the loop:

Beyond foreach and cw, Visual Studio 2010 has numerous code snippets. For example, if you need to build a custom System.Exception derived class which conforms to best practices, just type exception TAB TAB somewhere in a namespace scope.
Strictly speaking, VS 2010 supports two types of code snippets. The first batch are simple snippets that dump code at the current position of the text caret in the editor. You can view all snippets of this category by right clicking in your code editor and selecting the Insert Snippet?. context menu:

At this point you will find a list of al snippets (possibly arranged into categories based on what you have installed on your DEV machine) and a bit of help text. Make sure to take some time to try out a few which interest you.
The other category of code snippets are termed ?Surround with snippets?. As the name implies, you first select a set of code statements, right click on the selection, and pick a snippet. The selected code will then be wrapped in the snippet?s scope. For example, let?s say you want to wrap your foreach logic in a custom #region / #endregion. Begin as so:

Then pick #region from the menu selection:

Once again at this point, you can specify any required placeholders.

Beyond using the built in code snippets, you can certainly build your own! Many moons ago (2005 I believe?) I wrote an article for MSDN about how you can build custom code snippets. You can view this article at the MSDN web site here.
So there you go. A few helpful thoughts on working with code snippets. Enjoy!
2a9e8df4-7c16-44e4-a68a-13b9649d0c27|1|5.0