Surround-with Code Snippets in Visual Studio
By | January 8, 2012

Surround with” is a very nice features in Visual Studio IDE. The overall objective of this features is to surround the code snippets with a set of statement or controls very easily. Let’s assume that, you have set of code block which you want to put inside a if statement, so instead of writing the statement complete, first select the code block, right click and select “Surround with” from context menu.

This will display the available snippet for surround with.  Select any one them ( As part of this example we select if ) as shown in below:

image thumb2 Surround with Code Snippets in Visual Studio

This will automatically wrap the selected code snippet with the “Surround with” snippet.  As show in below image, select code blocked surrounded with “if” statement.

image thumb3 Surround with Code Snippets in Visual Studio

If you are an ASP.NET developer, you can use the same features in HTML Markup as well.  Select the HTML Code Block and select “Surround With” from context menu.

image thumb4 Surround with Code Snippets in Visual Studio

This will launch similar code snippet option for html control. Select the snippet and you are done !

image thumb5 Surround with Code Snippets in Visual Studio

Not only html controls, the similar snippet is available for ASP.NET Control as well. image thumb6 Surround with Code Snippets in Visual Studio

You can do this using keyboard by using short cut key “CTRL +K , CTRL + S”.

 

Overall this features is very handy and also save lots of time during development. So go ahead and give a try icon smile Surround with Code Snippets in Visual Studio

Cheers !

Abhijit