Auto-Format your Code in Visual Studio

Friday, July 18, 2008

Many a times we often come across unformatted code, which is almost impossible to understand. For instance, some lines of code may be indented properly while others might not be. Visual Studio provides a great feature for auto-formatting your unformatted code. Just press Ctrl+K followed by Ctrl+D and voila the code is now in a well-indented, easy to understand format. It works for markup code like HTML, XML etc. as well as for language codes such as C# and VB.

If you have code like this:


It can be auto-formatted to:


So, next time you copy some code from the net you can easily reformat it by using the key combination. Alternately, you can also use Ctrl+K followed by Ctrl+F.


Post a Comment