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
But, you want you code to be look like as below
Well, if you don’t know the trick, you have to do it manually. But VS provides you to enable this features automatically.
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.
Now once you unchecked the
“Leave block on Single line” checkbox, you can see the change reflected on example itself.
Similar, you can use the second checkbox option for “Same line Multiple Statement declaration”. As for example you have below set of code
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