How to Wrapping Code Block and Statements in Visual Studio ?

By | April 23, 2011

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

2 thoughts on “How to Wrapping Code Block and Statements in Visual Studio ?

  1. Pingback: TOD : Wrapping Code Block and Statements in Visual Studio « Abhijit's World of .NET

  2. Pingback: How to Wrapping Code Block and Statements in Visual Studio … | Learn Visual Studio

Comments are closed.