A C# formatter restructures C# code to follow the Allman brace style used in Microsoft's official .NET documentation — opening braces on their own line, aligned with the preceding statement. The formatter handles namespaces, classes, interfaces, properties, methods, async/await, and LINQ queries with proper indentation at each level.
Formatted C# will appear here...
Example Snippets
How to Use the C# Formatter
C# is the primary language of the .NET ecosystem, and the official Microsoft coding conventions specify Allman brace style — opening braces on their own line. This C# formatter applies those conventions in your browser, no Visual Studio or .NET SDK required.
Step 1: Paste Your C# Code
Copy your C# code — a namespace, a class, a method, or a full file — and paste it into the input area. The formatter handles namespaces, classes, interfaces, structs, properties, methods, constructors, if/else, for/foreach, while, do-while, try-catch-finally, switch, async/await, and LINQ syntax.
Step 2: Choose Indentation
Visual Studio defaults to 4 spaces, which matches Microsoft's C# coding conventions. You can also choose 2 spaces or tabs if your team or project uses a different standard via an .editorconfig file.
Step 3: Format or Minify
Click Format C# to apply Allman-style formatting with syntax highlighting. Click Minify to strip comments and collapse whitespace — useful for creating compact code examples or measuring code reduction after cleanup.
C# Formatting Best Practices
Microsoft's C# coding conventions specify: Allman braces (opening { on its own line, aligned with the statement above), 4-space indentation, blank lines between method declarations, attributes on the line before the method or class they annotate, and using directives at the top. Following these conventions makes .NET code immediately readable to any C# developer and aligns with the output of Visual Studio's auto-format feature.
FAQ
Is the C# formatter free?
Yes, completely free with no signup required. Format unlimited C# code in your browser at no cost.
Is my C# code safe?
Yes. All formatting runs locally in your browser using JavaScript. Your code is never sent to any server.
What brace style does this use for C#?
Allman style (also called BSD style) is the standard for C# and .NET — opening braces go on a new line aligned with the preceding statement. This is the style used in official Microsoft documentation and the .NET runtime source code.
What C# constructs does the formatter handle?
The formatter handles namespaces, classes, interfaces, properties, methods, constructors, if/else, for/foreach loops, try-catch-finally, switch statements, async/await methods, and LINQ queries.
Can I minify C# code?
Yes. The Minify button strips // and /* */ comments and collapses whitespace — useful for diff comparisons or measuring code length before and after refactoring.
Can I change indentation from 4 spaces?
Yes. Choose 2 spaces or tabs from the indent dropdown. The default is 4 spaces, which matches Visual Studio's default setting and the C# coding conventions from Microsoft.