Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Useful list of visual studio 2010 C# intellisense code snippets [closed]

I'm seeking a list of C# code snippets that would make our work faster inside visual studio 2010.

PS. I'm talking about code snippets in visual studio as the extension. Ctrl+K, Ctrl+X, to access code snippets....

For example, I saw one in a screen cast where the guy typed 'pi' and pressed some other button. The snippet created this for him:

private int _{namehere};
public int {namehere} {
    get{ return _{namehere}; }
    set{ _{namehere} = value; }
}
like image 362
Shawn Mclean Avatar asked Sep 20 '10 14:09

Shawn Mclean


1 Answers

Snippets that will make "MY" work faster in VS2010, won't necessarily make "YOUR" work faster. I use an assortment of snippets for tasks that I either repeat often, or for tasks that I do so seldom that I can't remember exactly how to do them without referencing previous work or examples. I use snippets mostly related to DICOM and imaging. Those wouldn't be very useful to most people.

I think that what would do you the most good would be to create your own library of snippets that would be items that you would commonly use in YOUR code. Refer to the first link on the page you've linked in your question to learn how to create your own snippets.

There are also several useful snippet editors and creators out there like Snippet Editor and Snippet Creator that can help with managing and modifying your snippets.

Specifically, for the snippet you refer to, save the following as a .snippet file and place it in your "My Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets\" folder:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Public Integer Property</Title>
      <Author>md5sum</Author>
      <Description>Creates a private integer member with a public integer property</Description>
      <HelpUrl />
      <SnippetTypes />
      <Keywords />
      <Shortcut>pi</Shortcut>
    </Header>
    <Snippet>
      <References />
      <Imports />
      <Declarations>
        <Literal Editable="true">
          <ID>varName</ID>
          <Type>int</Type>
          <ToolTip>The name of the variable.</ToolTip>
          <Default>VarName</Default>
          <Function />
        </Literal>
      </Declarations>
      <Code Language="csharp" Kind="method decl" Delimiter="$"><![CDATA[private int _$varName$
    public int $varName$
    {
        get
        {
            return _$varName$;
        }
        set
        {
            $varName$ = value;
        }
    }]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
like image 60
Nathan Wheeler Avatar answered Oct 16 '22 17:10

Nathan Wheeler