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
How to Wrapping Code Block and Statements in Visual Studio

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

How to Wrapping Code Block and Statements in Visual Studio
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.
How to Wrapping Code Block and Statements in Visual Studio

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

How to Wrapping Code Block and Statements in Visual Studio

Similar, you can use the second checkbox option for “Same line Multiple Statement declaration”. As for example you have below set of code
How to Wrapping Code Block and Statements in Visual Studio
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
How to Wrapping Code Block and Statements in Visual Studio

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s