Some code segments or tool functions are common in different projects. It is often used to search for a previous code segment to open a large project. After a long wait, copy and paste the code, which affects the efficiency.
You can use the code segment manager of VS to add your own code for future calls.
For example, a function for creating a DataTable is as follows:
Code
The following steps are required to join the code snippet Manager:
1. create the code snippet file GetDemoDataTable. snippet. create an xml file in vs, use the combined shortcut key CTRL + K + X in the XML file, select the Snippet code segment, and press the Tab key, you will find that Code Snippets also writes Code segments for creating Code segments.
<? Xml version = "1.0" encoding = "UTF-8"?>
<CodeSnippet Format = "1.0.0" xmlns = "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title> Title </Title>
<Author> Author </Author>
<Shortcut> Shortcut </Shortcut>
<Description> Description </Description>
<SnippetTypes>
<SnippetType> SurroundsWith </SnippetType>
<SnippetType> Expansion </SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID> name </ID>
<Default> value </Default>
</Literal>
</Declarations>
<Code Language = "XML">
<! [CDATA [<test>
<Name> $ name $ </name>
$ Selected $ end $ </test>]>
</Code>
</Snippet>
</CodeSnippet>
To:
<? Xml version = "1.0" encoding = "UTF-8"?>
<CodeSnippets xmlns = "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format = "1.0.0">
<Header>
<Title> GetDemoDt </Title>
<Author> zbl </Author>
<Shortcut> GetDemoDt </Shortcut>
<Description> Create a demo able </Description>
<SnippetTypes>
<SnippetType> SurroundsWith </SnippetType>
<SnippetType> Expansion </SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language = "csharp">
<! [CDATA [
Public DataTable GetDemoDt ()
{
DataTable dt = new DataTable ();
Dt. Columns. AddRange (new DataColumn [] {new DataColumn ("student ID"), new DataColumn ("name ")});
For (int I = 1; I <20; I ++)
{
DataRow dr = dt. NewRow ();
Dr ["student ID"] = I. ToString ("0000 ");
Dr ["name"] = "name" + I. ToString ();
Dt. Rows. Add (dr );
}
Return dt;
}
]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
After comparing the two files, you can find out where the changes are made and find the meaning of each node on msdn. Save the modified xml file as the. Snippet file.
2. Import the code snippet File
Tool-code snippet Manager-import-select C #
3. Use a code segment File
Right-click the project and choose external code, for example:
Have a good reference article http://www.cnblogs.com/tannaiyin/archive/2009/04/04/1429316.html
However, csharp was written as cshap, and it took me five minutes to find this error, but thanks to the blogger.