Format C# code

Paste C# code squeezed onto one line or poorly indented: the tool re-indents every { } block (classes, methods, conditions, loops) and puts one statement per line, for instant readability.

Warning: this is a basic indentation formatter, not a full tool like Visual Studio's built-in formatter. It doesn't check that the code compiles and doesn't reorganize all the spacing around operators.

Example:

How it works

The tool reads C# code character by character with a small state machine that can spot strings (regular double-quoted strings as well as verbatim strings @"...") and comments (//, /* */), so it never touches a brace or semicolon inside a literal. Each opening brace adds an indentation level of 4 spaces, each closing brace removes one, and a semicolon outside parentheses marks the end of a statement.

Can formatting break the project build?

No, the tool only touches formatting (spacing, line breaks, indentation) and leaves identifiers, types, and statement order intact. The reformatted file compiles exactly like the original as long as the original was already valid.

Are interpolated strings ($"...") handled correctly?

The quotes that delimit an interpolated string are recognized like those of any regular string, so their content is never split by mistake. However, the formatter doesn't specifically re-indent the { } expressions inserted inside an interpolation, since they stay within the string.

Formatting runs 100% locally in your browser: your C# code is never sent to a server.