Formatting and code cleanup in Visual Studio
It turns out that Visual Studio can automatically arrange and even clean up your code in a consistent manner through built-in features.
Formatting documents
One of the easiest ways to do this is with the Format Document feature, either by pressing Ctrl + K and then Ctrl + D or by opening the Edit menu, then going to Advanced and selecting Format Document, as shown in Figure 16.1:
Figure 16.1 – Formatting the active editor document
This will change the code in your current file to match the preferences you’ve configured in Visual Studio.
These settings can be configured by opening the Tools menu and then selecting Options…. From there, expand the Text Editor, C#, Code Style, and Formatting nodes until you see the various preferences for indentation, new lines, spacing, and wrapping.
These settings blades allow you to configure the formatting preferences of Visual Studio and preview...