jump to navigation

Code Snippets – List of C# snippets in VS2008 May 6, 2009

Posted by codinglifestyle in C#, CodeProject, Visual Studio, Visual Studio 2010.
Tags: , , ,

In VS2010 we are told to expect a lot more code snippets.  To be honest, I don’t use them much but watching the demo I told myself it was time to give them another look.  Sometimes I get a great feeling of productivity in hammering out for loop templates and properties and tell myself who needs snippets?  But there is a lot of power there, and its going even further in VS2010.

My problems is I can never remember which code snippets are there.  I occassionaly see them in Intellisense, but there is so much there it’s hard to pick them out.  More than once I’ve carefully gone through the intellisense list trying to pound the useful ones in to my brain.

I decided to do a quick search for a list of code snippets in VS2008 for C#.  Surely I can’t be the first who just wants a simple list, right?  I came across Francesco’s blog who posted the code to iterate through your snippets and output them.  A quick change to update it for VS2008, C#, and to output a comma delimited line per snippet, then a paste in to Word, and Convert Text to Table (by comma) and voila!

List of Code Snippets in VS2008 for C#

#if Code snippet for #if
#region Code snippet for #region
attribute Code snippet for attribute using recommended pattern
checked Code snippet for checked block
class Code snippet for class
ctor Code snippet for constructor
~ Code snippet for destructor
cw Code snippet for Console.WriteLine
do Code snippet for do…while loop
else Code snippet for else statement
enum Code snippet for enum
equals Code snippet for implementing Equals() according to guidelines
exception Code snippet for exception
for Code snippet for ‘for’ loop
foreach Code snippet for foreach statement
forr Code snippet for reverse ‘for’ loop
if Code snippet for if statement
indexer Code snippet for indexer
interface Code snippet for interface
invoke Code snippet for safely invoking an event
iterator Code snippet for a simple iterator
iterindex Code snippet for ‘named’ iterator/indexer pair using a nested class
lock Code snippet for lock statement
mbox Code snippet for MessageBox.Show
namespace Code snippet for namespace
prop Code snippet for an automatically implemented property
propg Code snippet for an automatically implemented property with a ‘get’ access or and a private ‘set’ accessor
sim Code snippet for int Main()
struct Code snippet for struct
svm Code snippet for ‘void Main’ method
switch Code snippet for switch statement
try Code snippet for try catch
tryf Code snippet for try finally
unchecked Code snippet for unchecked block
unsafe Code snippet for unsafe statement
using Code snippet for using statement
while Code snippet for while loop

You can see snippet’s keyword typically matches the operator.  So next time you type for or while or try remember to hit TAB-TAB to expand the snippet.  Next time we’ll look at making your own code snippets.



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: