Visual Studio Tip: Use Code Snippets

There is a little used function of Visual Studio that will save you a lot of coding time: Code Snippets. Code Snippets are handy key shortcuts that expand into commonly used .NET constructs such as regions, constructor, loops (do/while/for/foreach), and try/catch blocks. To use a code snippet you can type in its 'shortcut' and in Intellisense you will see a little piece of paper next to the word indicating that it is indeed a code snippet. Then you press TAB twice, and the code snippet is expanded into the full construct, and depending on the snippet you may be directed to enter some pertinent information.

Let's try my favorite example: a property declaration with a backing field.

  1. Type in prop and then press TAB twice
  2. You will see an expanded property declaration with green fields, indicating that you need to supply this information.
  3. The first field to fill in will be highlighted in blue, which in this case is 'int'. Let's type 'string' to make a string property, but any .NET type will work.
  4. Now hit TAB again to go to the next field, which is the name of the private variable. Let's call it _stringProperty.
  5. Press TAB again to go to the public property name. Notice that it filled in the get/set values of the private variable for you. Now you can call the public string StringProperty, and press ENTER to indicate that you are finished (if you press TAB, you will cycle back through the customizable fields).

Now this saves me a lot of time since I can create properties rapidly instead of typing curly braces and get/set over and over. Other huge time savers include foreach/for, try, and cw (which does a Console.WriteLine()).

4 Comments

  • people were the best 9th set of Miu Miu Outlet, and therefore i cherish them all the more, they are just plain just the thing for with less time resting at the dance club! i become a large number of compliments pictures supply them all!! they are just plain necessity, without a doubt:)

  • I have been browsing online more than 3 hours today, yet I never found any interesting article like yours. It抯 pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the web will be a lot more useful than ever before.

  • uncertain about precisely how weather conditions resiliant blade & soul gold are generally yet very hot together with been given loads of kind comments....lovely by using small trousers....

  • We have Various pairs from swtor credits. I own a taller typical combine usually bring in sole mainly because men's slippers inside the camera. I own a concise combine along with the sole regarding out-of-doors winter season bring in, these are typically great. When i possess a different concise combine. Lv all of the gray. Simply put i bring in anytime, or maybe when ever my paws are actually amazing or maybe lonely...Amazing merchandise.

Comments have been disabled for this content.