Posts
20
Comments
10
Trackbacks
0
Useful C# snippets
I recently sat down at my computer at home, opened up Visual Studio and came to the realisation that I cannot program at home. I cannot program at home, not because I have cool games to play (everyone please check out Burnout Paradise, it is awesome), not because I have fun series to watch (once again, WHY did they cancel FarScape), but merely because my computer at home is just not set up to program!

I don’t have any of the cool things set up like they are at work. This as you all know is a sad situation to be in and since I started this blog to be a place where I could put useful stuff, I decided that I should start doing exactly that. (That or I am just procrastinating, because I cannot work at home!)

Visual Studio introduced snippets quite a while ago and I have to say that in most cases I do not use them. Mostly one will see snippets in demo videos where the presenter does not show how badly he types. Though there is one personal snippet that I cannot live without as I learnt this morning. This snippet we affectionately refer to as sgs, Short Get Set.
Type in sgs, hit Tab and you will end up with { get; set;}. 4 key presses for 12, quite a good deal I think. Also remember developers can’t type!

With a short amount of searching I was able to find the MSDN page that shows you how to make a snippet, and recreated my beloved sgs. Below is the code. Save it as sgs.snippet into your \Documents\Visual Studio 2008\Code Snippets\Visual C#\ folder and the next time you type sgs and Tab it will work!

    1 <?xml version="1.0" encoding="utf-8"?>

    2 <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

    3   <CodeSnippet Format="1.0.0">

    4     <Header>

    5       <Title>Short get set</Title>

    6       <Shortcut>sgs</Shortcut>

    7       <Author>FryHard</Author>

    8       <HelpUrl>blog.fryhard.com</HelpUrl>

    9     </Header>

   10     <Snippet>

   11       <Code Language="CSharp">

   12         <![CDATA[{get; set;}]]>

   13       </Code>

   14     </Snippet>

   15   </CodeSnippet>

   16 </CodeSnippets>

posted on Saturday, February 28, 2009 10:55 AM Print
News