..


Sponsored Links

The Visual Studio code snippets

Article written by Vincent Gaglio
Page 1 of 3

A code snippet (translated into Italian 'snippet') is a small piece of code that you can put in an application and then edit to suit your needs. The aim is to speed up the planning stage, with coding by automating the inclusion of the most used or whose syntax is hard to remember.

In particular in the development environment Microsoft Visual Studio (since version 2005) has been paid great attention to the management of code snippets, and this has greatly improved the efficiency of programming, especially in those who perform repetitive tasks with similar purposes.

In early versions of the development of Redmond and the process of making use of them was very simple, provided you select the first piece of code to be created as a snippet in the Toolbox and drag. Following this same snippet was created and if for example you wanted to create the following piece of code snippet






 / / This is my snippet







 if (/ * condition * /)







 {



  



 / / Instructions







 }







 else







 {



  



 / / Instructions







 }



just write the content in the text editor of Visual Studio, select it and drag it to the Toolbox. Once this is done in something like that appeared Toolbox

with the ability to rename the newly created item to your liking. When you later want to use the snippets from the Toolbox, just drag it to your code.

Over the years the technology has evolved code snippets, and today, while remaining available opportunity to do what we have just seen, this functionality is handled differently. In later versions of Visual Studio snippets fact consist of an XML file that can include simple code (like above) but also references, parameters, etc.. The fact that these elements are also encoded in XML makes it possible to share them with other programmers.

Visual Studio provides several predefined snippets encoded in the three main languages. NET Framework (C #, VB.NET and J #) and can be used by menu items or keyboard shortcuts. When you locate the position of the code where you want to insert a snippet it is possible to do one of the following:

  • From the keyboard press Ctrl + K, Ctrl + X
  • Click the right mouse button on the insertion point and select Insert Snippet
  • Click on the Edit menu, select IntelliSense, and then Insert Snippet

By making one of these operations appears to us the list Insert Snippet. By scrolling with the mouse and pausing on one of the Visual Studio displays a tooltip indicating the corresponding code will be inserted by clicking on the selected item

In the same category ...
E-Learning
Front Page (Ebook) Front Page (Ebook)
Create Web pages without knowing HTML. Just 25 €.
Web Design (Course) Web Design (Course)
Design Web Sites with HTML, CSS and Dynamic HTML. From 39 €.
Sponsored Links