Surround-with Code Snippets in Visual Studio

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

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

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

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

image

Not only html controls, the similar snippet is available for ASP.NET Control as well. image

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 🙂

Cheers !

Abhijit

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.