Format
Rewrites your C# with consistent braces, spacing, and indentation using clang-format. Turns cramped or messy code into clean, readable source.
class User{public int Id{get;set;}}Afterclass User
{
public int Id { get; set; }
}Paste cramped or messy C# and get it back with consistent braces, spacing, and indentation. The formatter is clang-format, running in your browser, so your code stays on your device.
Format uses clang-format. The style and indent options apply to Format.
C# lets you put braces, spaces, and line breaks almost anywhere, so code pasted from different places can look very different. A formatter, also called a beautifier, rewrites the source with one consistent set of rules: braces in the same place, even indentation, and clean spacing around operators and properties. This tool uses clang-format and changes only the layout, never what the code does.
Rewrites your C# with consistent braces, spacing, and indentation using clang-format. Turns cramped or messy code into clean, readable source.
class User{public int Id{get;set;}}Afterclass User
{
public int Id { get; set; }
}Pick the style clang-format follows. Microsoft, the default, puts each opening brace on its own line like most .NET code. LLVM and Google keep the brace on the same line.
Microsoft, LLVM, Google...AfterYour chosen brace styleChoose 2 or 4 spaces for each level of nesting. Most C# projects use 4, which is the default here.
2 spaces or 4 spacesAfterYour choice per levelCode inside a namespace block is always indented one level, which matches how Visual Studio and dotnet format lay out C#.
namespace Demo{class A{}}Afternamespace Demo
{
class A
{
}
}A formatter helps whenever C# is hard to read or needs to match a shared style. These are the cases that come up most:
Once your C# is formatted, these references explain the language and its usual style:
This tool uses clang-format, which supports C# and gives fast, consistent brace and indent layout. In a .NET project you have two options:
| To | Use |
|---|---|
| The built-in .NET formatter | dotnet format, which follows the rules in your .editorconfig file |
| The same engine as this tool | clang-format -i Program.cs with a .clang-format file |
| Format on save | Visual Studio and VS Code with the C# extension can format on save using .editorconfig |
dotnet format is what most C# teams use, because it also applies .NET naming and code style rules. Use this tool for quick cleanups, and letdotnet format enforce your project's rules.
If you work across languages, these formatters run the same way, right in your browser: