How to Wrapping Code Block and Statements in Visual Studio ?

In this tips I am going to describe how you can automatically wrap up code blocks or code statement in Visual Studio. We can use Document formatting to format the whole contents, but that doesn’t wrap single line code block like Properties or not even single line multiple declaration statement.  Let’s consider an example, you are creating a Properties using code snippet and by default it will came up like

image

But, you want you code to be look like as below

image

Well, if you don’t know the trick, you have to do it manually. But VS provides you to enable this features automatically.

Goto Tools > Options > Text Editor > C# > Formatting > Wrapping. As shown in below image, by default “Leave block on Single line” is Checked. You can also see the example of “Age” Properties. 

image

Now once you unchecked the “Leave block on Single line” checkbox, you can see the change reflected on example itself.

image

Similar, you can use the second checkbox option for “Same line Multiple Statement declaration”. As for example you have below set of code

image

this is the default behavior of VS Code Editor. Now, if you want put all the statement in different line, instead of doing it manually you can use the “Leave Statements and member declarations on the same line” check box.

This will automatically changed the line as

image

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.

2 Comments to “How to Wrapping Code Block and Statements in Visual Studio ?”

Comments are closed.