C# Beautifier

Format C# code with Allman braces or other styles.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

C# Beautifier – Format C# Code Online

The C# beautifier formats C# code with clang-format, running locally in your browser via WebAssembly. Paste a class, a LINQ query, or a whole file and get consistently indented code with your preferred brace style.

What it formats

  • Namespaces (block-scoped and file-scoped), using directives, classes, structs, interfaces, and records.
  • Properties with getters and setters, expression-bodied members (=>), and auto-properties with initializers.
  • LINQ method chains and lambdas, async/await, pattern matching, and string interpolation.
  • Attributes, generics with constraints, and events.

Style presets

clang-format ships with the coding styles of well-known projects:

  • LLVM – 2-space indentation in LLVM itself (configurable here), braces on the same line.
  • Google – Google's style guide; the usual choice for Java and many C++ projects.
  • Chromium and Mozilla – the browsers' variants of the Google and LLVM styles.
  • WebKit – 4-space indentation, function braces on their own line.
  • Microsoft – Allman braces (every brace on its own line), common in C# and Windows code.
  • GNU – the GNU coding standards with half-indented braces.

You can override the indentation (2 or 4 spaces or tabs) and the column limit (80, 100, 120, or no limit) on top of any preset.

For C#, the Microsoft preset is selected by default. It uses Allman braces — every opening brace on its own line — and 4-space indentation, which matches the default formatting of Visual Studio and the .NET runtime coding guidelines.

How to use it

Paste your code or click Sample, choose the style, indentation, and column limit, then copy the formatted C# or download it as a .cs file.

Formatter, not compiler

clang-format formats tokens and does not compile your code, so it will not report type errors or missing references. It also leaves using order and member order unchanged. For .NET-specific rules like var preferences or naming, use dotnet format with an .editorconfig.

Format XAML views with the XAML Beautifier, JSON configuration such as appsettings.json with the JSON Beautifier, and SQL queries with the SQL Beautifier.

Frequently Asked Questions

The Microsoft preset produces Allman braces and 4-space indentation like Visual Studio's defaults. Some details, such as spacing in specific constructs, can differ from Roslyn's formatter.

Yes. Modern C# syntax such as file-scoped namespaces, records, init-only setters, and pattern matching is formatted.

No. Only whitespace and line breaks change; tokens and their order stay the same.