[Collection] code segment (code snippets)

Source: Internet
Author: User

1.CodeSegment (code snippets)

The code segment in VISAUL Studio 2005 greatly saves some boring and non-technical coding work, such as setting attributes of entity classes.

In Visual Studio 2005, the VB. NET code segment is much more than that of Visual C #. Is it attractive to developers?

You can modify the existing snippet files in the system (c: \ Program Files \ Microsoft Visual Studio 8 \ Vc # \ snippets \ 2052 \ Visual C # directory) to add your common snippet files.

On the Internet (http://www.gotcodesnippets.net/) also has a lot of other people compiled snippet, can be used as needed.

To share or publish snippet, you 'd better make it into the format VSI supported by Visual Studio, which is actually a zip file with the suffix changed, it contains an XML description file, one or more snippet files (you can obtain a VSI file from the above website to refer to how to create the file ).

In Visual Studio 2005, the shortcut for inserting a code segment is ctrl k + ctrl X, and the shortcut window for the code segment manager is ctrl k + ctrl B.

Example:
When we write a select Branch (if statement) or a loop Branch (for statement), do we need to finish each character completely manually?
Of course it won't be so stupid. We just need to enter "if" and then press the tab key twice, and the classic structure of the IF statement will jump to the paper.
In this case, you only need to write the conditions in the green box.

When you see this, you will surely scream: I have used this for a long time!
Yes, this is the code segment. It not only supports if, but also supports for, do, switch, and other common C # statements.
There are several ways to insert a code segment: 1. Right-click the editing area and select "insert code segment"
2. Shortcut Keys Ctrl + k, X

Similarly, you can select prepared statements and insert "outer code segment". The selected statements are surrounded by the selected code segment.
Here is an example:

String Name = Labname. text;

Response. Write (name );

As shown above, we output the name content to the page. However, we also consider whether to add a name to determine whether the content is empty. What should I do?
Write an if statement, insert the code segment with a tab, and then copy and paste it?
This is not necessary. Select the second sentence, right-click it, and select "outer code" (or press Ctrl + k, S). Select "if ", we can see that the statement is automatically placed in the IF statement structure.

If ( True )
{
Response. Write (name );
}

Is it very convenient, especially when the code is complex.

More than that, when we open "tool" and "code segment manager" in vs2005 and select the "Visual C #" node, we will find all the code segments that Ms has defined for us.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.