Click here to Skip to main content
13,048,846 members (68,874 online)
Click here to Skip to main content
Add your own
alternative version

Stats

12.5K views
8 bookmarked
Posted 31 Mar 2011

Code Snippets – List of C# snippets in VS2008

, 31 Mar 2011
Rate this:
Please Sign up or sign in to vote.
A list of C# snippets in VS2008.

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 it's going even further in VS2010.

My problem is I can never remember which code snippets are there. I occasionally 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 one 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#

#ifCode snippet for #if
#regionCode snippet for #region
attributeCode snippet for attribute using recommended pattern
checkedCode snippet for checked block
classCode snippet for class
ctorCode snippet for constructor
~Code snippet for destructor
cwCode snippet for Console.WriteLine
doCode snippet for do…while loop
elseCode snippet for else statement
enumCode snippet for enum
equalsCode snippet for implementing Equals() according to guidelines
exceptionCode snippet for exception
forCode snippet for ‘for’ loop
foreachCode snippet for foreach statement
forrCode snippet for reverse ‘for’ loop
ifCode snippet for if statement
indexerCode snippet for indexer
interfaceCode snippet for interface
invokeCode snippet for safely invoking an event
iteratorCode snippet for a simple iterator
iterindexCode snippet for ‘named’ iterator/indexer pair using a nested class
lockCode snippet for lock statement
mboxCode snippet for MessageBox.Show
namespaceCode snippet for namespace
propCode snippet for an automatically implemented property
propgCode snippet for an automatically implemented property with a ‘get’ access or/and a private ‘set’ accessor
simCode snippet for int Main()
structCode snippet for struct
svmCode snippet for ‘void Main’ method
switchCode snippet for switch statement
tryCode snippet for try catch
tryfCode snippet for try finally
uncheckedCode snippet for unchecked block
unsafeCode snippet for unsafe statement
usingCode snippet for using statement
whileCode snippet for while loop

You can see the snippet’s keyword typically matches the operator. So the 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Chris_Green
Architect Avaya Inc.
Ireland Ireland
Formerly a C++ client developer, nowadays I'm all about C# and ASP.NET. Over the years I have mastered some and played with many aspects of .NET.

Follow my blog as I catalogue the more arcane problems I encounter and their solutions at CodingLifestyle.com

You may also be interested in...

Pro

Comments and Discussions

 
QuestionFrancesco's Blog Link Pin
Doncp1-Apr-11 16:38
memberDoncp1-Apr-11 16:38 
AnswerRe: Francesco's Blog Link Pin
newkie4-Apr-11 0:37
membernewkie4-Apr-11 0:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 31 Mar 2011
Article Copyright 2011 by Chris_Green
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid