Another benefit of Code Snippet is to minimize errors. Code Snippet is usually simple code, but sometimes retyping these code is also vulnerable. A good example is the Select case structure in VB.NET, we easily lack the "Case Else" code when programming, but thanks to Code Snippet we will never be missing this code.
VS 2005 does not limit the number of Code Snippet created. You can create or use, change (such as extended functionality) available Snippet Code.
Create new Code Snippet
Code Snippet in VS 2005 Picture 1 Code Snippets is created in XML file format. To view the Code Snippet XML file structure, you can open an existing file or find out at http://msdn2.microsoft.com/en-us/library/ms171418.aspx. You can create Code Snippet by creating a structured .snippet file in XML format as instructed on the website above. However, this approach is very unpopular and easy to get bored with programmers.
The easiest way to create the Code Snippet is to use Visual Basic Snippet Editor. This is the Code Snippet creation utility developed by Microsoft. You can download the Visual Basic Snippet Editor at http://go.microsoft.com/fwlink/?LinkId=46593.
Suppose you want to build Code Snippet to read a value in Session when you know the data table name, data field in the data row to read, create Code Snippet as shown below:
In it, the part between two $ signs is the parameter to change the value, the name for Code Snippet. To add a parameter to Code Snippet, select Replacements Tab, double-click on the parameter name and click the (+) icon.
Use Code Snippet
To use Code Snippet you must copy the .snippet file to the C: Documents and SettingsAdministratorMy DocumentsVisual Studio 2005Code SnippetsVisual BasicMy Code Snippets of VS2005. In addition, you can also copy them to the existing Code Snippet folders of VS2005.
If you use the Visual Basic Snippet Editor, this tool will automatically copy the Code Snippet file into the Code Snippet folder.
To insert Code Snippet, in the VS 2005 editor window, press Ctrl + K + X, a Code Snippet menu is displayed. Select Code Snippet, press Enter, then select Code Snippet name and Code Snippet will be inserted into the cursor position.
Conclude
Thanks to Code Snippet, programming time is significantly reduced. The most critical thing is that we have to look at which code snippets are often used to create Code Snipet for later use. Of course, it is also possible to create a Code Snippet that is only used once in the application, but this is time-consuming.
There are currently two organizations specializing in the research and creation of Code Snippet introduced at the website: http://DotNetJunkies.com and http://GotCodeSnippets.com.
Duong Ba Hong Minh Email: minhdbh@yahoo.com Reference:http://msdn.microsoft.com/msdnmag/issues/06/04/AdvancedBasics/ http://msdn2.microsoft.com/en-us/library/ms171418.aspx.