Code Snippets in Visual Studio 2010

Code Snippets are ready made code which can be inserted to our Application. It Minimizes the error and saves lot of Development Time. C# Code Snippets are included in Visual Studio 2008. In Visual Studio 2010 ASP.Net, HTML and JavaScript Snippets were introduced. Find Code Snippets in Visual Studio 2010

What are Code Snippets?

It is ready made code, which can be directly inserted to our program or Application.

Code Snippets - Features

1. Pre-developed code template which can insert into our code.
2. Quickly applied with minimum keystorkes.
3. Inserts the basic skeleton for any code.
4. Inserted to current cursor location.

Code Snippets - Advatanges

1. Minimizes the Error.
2. Saves Development Time.

Code Snippets - Types

1. Expanded - inserted at the current cursor location.
2. Surrounded - wraps around the selected code block.

Adding Code Snippets to the Program

1. Press Ctrl + K and then CTRL + X.
2. Edit -> IntelliSense -> Insert Snippet Option
3. Type Code Snippet starting name and press Tab key.

Visual Studio Code Snippets

1. C# Code Snippets [Introduced in VS 2008]
2. ASP.Net, HTML and JavaScript [Introduced in VS 2010]

1. C# Code Snippets

1. Programming Statement Code Snippets
if, switch, while, for, do and foreach
Example: do-while loop


} while (true);

2.Exception code Snippets
exception, try
Example: try block

catch (Exception)

3.Declaration code Snippets
class, interface, namespace and struct
Example: class

class MyClass

2. ASP.Net, HTML and JavaScript Code Snippets

A. ASP.Net Snippets
label, textbox, checkbox, listbox and gridview.
Example: listbox
<asp:ListBox runat="server">
<asp:ListItem Text="text1" />

B. HTML Snippets
anchor tag, table tag
Example: anchor tag
<a href="#">content</a>

C. JavaScript code Snippets
alert, funtion
Example: alert


Author: Mahesh Nagar11 Nov 2011 Member Level: Gold   Points : 0

tell me how can we define our own code Code Snippets .

Author: Vijayalakshmi G M11 Nov 2011 Member Level: Gold   Points : 0

Hi Mahesh,

Thanks for sending the mail.

Refer this link:
to create the your own snippet.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: