The Visual Studio Code Snippets feature allows very simple, common, code blocks to be reused without requiring the same thing to be typed out repeatedly, or copied and hacked. The Code Snippets feature allows inserting code, wrapping existing code and replacement of key parts of the Snippet.
The snippets themselves, of course, are just individual XML files that end in .snippet sitting in a bunch of folders
- Using Visual Studio default snippets (C#)
Some of the Code Snippets that are included with Visual Studio include properties, constructors, code blocks etc. You can find a list of built-in snippets here: http://john-sheehan.com/blog/cheatsheets/visual-studio-2008-csharp-snippets.htm. There are not a lot of them, but they are very useful once you’ve got accustomed to using them. Also, Microsoft have released a whole bunch of C# snippets that you can download from http://msdn.microsoft.com/en-gb/vstudio/aa718338.aspx
Remember that there are no “best” code snippets. There are snippets that are more “useful” than others, but no “best” snippets.
The easiest way to use a code snippet is to begin typing part of the snippet shortcut name, eg “prop” for property expansion. Once you’ve typed enough to uniquely select the snippet shortcut name, press: Tab, Tab and the snippet will be autocompleted.
If it’s a templated snippet Tab advances to the next field, Shift+Tab moves to the previous field, Enter completes the snippet and resumes editing at your previous cursor position
If you want to enclose code in a surrounding snippet (eg, you have code highlighted for a region), you must manually invoke snippet intellisense by pressing: Ctrl+K, Ctrl+X then select the snippet you need (#region, for, if etc) and press Tab, Tab.
- Creating and using custom snippets
You can either create new snippets or edit the built-in ones to suit your needs. (The Visual Studio snippets can be found at C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Visual C#.)
I found using custom snippets feature particularly useful when working extensively for a long period of time with a proprietary framework that handles common functions like displaying a custom message, getting various languages text resources etc. I can just add snippets for the code that is used very often, and voila! A piece of code in just a few clicks!
If you don’t want to get you hands “dirty” by creating / editing XML files directly, you can use a snippet editor (e.g. http://www.codeplex.com/SnippetEditor) that does all the XML formatting done, is easy to use and you can have fun with just the code.
Save the new snippet file that you created somewhere where you can locate it easily and switch to Visual Studio. Bring up the Code Snippets Manager with the keyboard shortcut chord Ctrl+K, Ctrl+B and add the folder where you saved your new snippet.
Once the Snippets have been added they can be accessed from the Snippets context menu (ctrl-k, ctrl-x or right click > insert snippet) or via shortcuts. The context menu will present the Snippets in the folder structure setup in the snippet manager.
It may take a bit of time to get accustomed to using them and creating your own, but on the long term it will be well worth it when they get into your work routine. Code Snippets can save you precious development time and save you from the frustrating, tedious reproduction of well-known code constructs that can make development really boring and annoying at times.
Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.