You could add the Editor Guidelines extension into Visual Studio:

https://marketplace.visualstudio.com/items?itemName=PaulHarrington.EditorGuidelines

I find it helpful to visually limit the length of lines of code, but it's not an automatic enforcement.

Answer from Ben Wesson on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1007988 › line-length-enforcement-for-visual-studio-and-dotn
Line length enforcement for Visual Studio and dotnet format? - Microsoft Q&A
September 14, 2022 - For books this is around 60. 60 is too few for code; for code it is typically 80-120 characters. Visual Studio and C#/.NET doesn't have a line length format option, same as the dotnet format tool.
Discussions

[Suggest] Supporting max_line_length in editorconfig
Suggest supporting max_line_length in editorconfig: https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#max_line_length More on github.com
🌐 github.com
2
September 6, 2019
.net - C# coding convention for line width - Stack Overflow
Possible Duplicate: C# coding style - line length / wrapping lines Is there a widely accepted coding convention for C#, and is there a suggested maximum line width? The 80 characters per line ... More on stackoverflow.com
🌐 stackoverflow.com
How to auto enforce code styles like 1 dot per line for chained methods?
When csharpier breaks long invocations it is one invocation per line, although it does group properties onto lines before the invocation. Which is maybe you what you are after. I'd say just use csharpier and forget about it, but I'm a bit biased as the creator. More on reddit.com
🌐 r/dotnet
31
27
July 10, 2024
Roslyn formatter should offer an option to enforce a maximum number of columns per line
Area-IDEFeature RequestIDE-FormatterCode formatter and/or smart indentCode formatter and/or smart indent ... One feature I am missing in Visual Studio is being able to automatically enforce a maximum line length. That is, if a line of code is too long, it automatically gets broken up into multiple ... More on github.com
🌐 github.com
5
August 26, 2020
🌐
GitHub
github.com › dotnet › format › issues › 367
[Suggest] Supporting max_line_length in editorconfig · Issue #367 · dotnet/format
September 6, 2019 - Suggest supporting max_line_length in editorconfig: https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#max_line_length
Author: dotnet
🌐
Developer Community
developercommunity.visualstudio.com › idea › 607970 › net-projects-support-for-max-line-length-property.html
support for max_line_length property in .editorconfig
Skip to main content · Visual Studio · Guidelines Problems Suggestions Code of Conduct · Downloads · Visual Studio IDE Visual Studio Code Azure DevOps Team Foundation Server Accounts and Subscriptions · Subscriber Access · Microsoft Security Azure Dynamics 365 Microsoft 365 Microsoft ...
Top answer
1 of 4
13

If I went with "what fits", without much thought other than that, I would be cramming 60 lines into a function at 260 characters per line, and could still argue that "it all fits on my screen". It does, and I'm not using a ridiculously small sized font either. (9 pt Courier New, 24-inch widescreen monitor at 1920x1200, with basically the whole screen real estate devoted to code; the solution explorer, code definition window, output window, error list and so on are on my second monitor.)

Everyone is going to have their own opinion, and personally I think 80 character line widths are a bit off in the other direction these days, but depending on exactly what it is about, I try to keep myself under 100-120 characters per line, including indentation. If it gets much longer than that, there's probably parts in it that can easily be broken out and put on separate lines in ways that improve readability.

Because that is what it really is about. Readability. I don't really care if you use 60 characters per line or 200, but when I have to work with your code, it had better be easy to read and easy to tell at a glance what it does.

Also, try to chunk your code in ways that will provide meaningful diffs that are, again, easy to read. That's another rule of thumb I try to stick to; if I compare two sets of files, I want to see the changes that actually matter, not kilometer-long lines where the only difference is a single character change (which may very well be a very valid change, but is difficult to find in such a behemoth).

2 of 4
2

I have two monitors, one is 26' and the other 22'. I use the smaller one to place utility windows as File Structure, Class view, Code definition, Object browser, To-do Explorer, Output, Error list, Pending changes (Ankh plug in) and so on. I leave the main window just for code and the project browser, so I told ReSharper set my line width to 160 characters (just in case I'd need some line to be that long). Normally I won't exceed 120 characters which is the length I feel most comfortable with. I'd feel really dumb if I had to work on this monitor with fewer than that.

The 80 characters per line made sense back in the day, when it was the standard width for monitors in text mode.

🌐
Infinum
infinum.com › handbook › dotnet › best-practices › code-style
.NET Handbook | Best Practices / Code Style
Line length should not be more than 120 characters. Always use braces. Format method parameters into separate lines.
Find elsewhere
🌐
Developer Community
developercommunity.visualstudio.com › idea › 567214 › support-max-line-length-in-editorconfig-for-visual.html
Support max_line_length in .editorconfig for Visual Studio
Skip to main content · Visual Studio · Guidelines Problems Suggestions Code of Conduct · Downloads · Visual Studio IDE Visual Studio Code Azure DevOps Team Foundation Server Accounts and Subscriptions · Subscriber Access · Microsoft Security Azure Dynamics 365 Microsoft 365 Microsoft ...
🌐
GitHub
github.com › dotnet › roslyn › issues › 47158
Roslyn formatter should offer an option to enforce a maximum number of columns per line · Issue #47158 · dotnet/roslyn
August 26, 2020 - I often find myself writing very long lines of code (up to 200 columns). However, I don't want to have to think about arranging and breaking up the code. This bad habit is enforced through very large monitors.
Author: dotnet
🌐
GitHub
github.com › belav › csharpier › issues › 142
80 character limit · Issue #142 · belav/csharpier
April 24, 2021 - Why does csharpier use the ancient 80 character limit per line? I realize this is a contentious (religious) issue and there is not "right" answer, but 80 is pretty narrow. In particular a...
Author: belav
🌐
GitHub
github.com › dotnet › format › issues › 246
Prettier-style line breaking · Issue #246 · dotnet/format
July 10, 2019 - It's my understanding the the project doesn't do line breaking the way Prettier does: Inserting and removing line breaks depending on the length of the resulting lines. I can't find a r...
Author: dotnet
🌐
GitHub
github.com › dotnet › roslyn › issues › 57263
Line length formatting to be apart of EditorConfig · Issue #57263 · dotnet/roslyn
October 20, 2021 - resharper_csharp_insert_final_newline = true resharper_csharp_max_line_length = 100 resharper_csharp_wrap_after_declaration_lpar = true resharper_csharp_wrap_after_invocation_lpar = true resharper_csharp_wrap_arguments_style = chop_if_long resharper_csharp_wrap_chained_method_calls = chop_if_long resharper_csharp_wrap_extends_list_style = chop_if_long resharper_csharp_wrap_parameters_style = chop_if_long resharper_outdent_dots = true resharper_wrap_array_initializer_style = chop_if_long resharper_wrap_before_first_type_parameter_constraint = true resharper_wrap_lines = true ... Area-IDEFeature RequestIDE-FormatterCode formatter and/or smart indentCode formatter and/or smart indentResolution-DuplicateThe described behavior is tracked in another issueThe described behavior is tracked in another issue
Author: dotnet
🌐
DeepWiki
deepwiki.com › dotnet › format › 5-configuration
Configuration | dotnet/format | DeepWiki
April 25, 2025 - The .editorconfig files in your codebase provide the primary configuration for code formatting rules. dotnet-format supports both core EditorConfig properties and .NET-specific coding conventions. The following core EditorConfig options are supported: Note: trim_trailing_whitespace and max_line_length are not currently supported.
🌐
JetBrains
jetbrains.com › help › resharper › EditorConfig_CSHARP_LineBreaksPageSchema.html
EditorConfig properties for C#: Line Breaks | ReSharper Documentation
May 26, 2024 - Formatting preferences listed on this page can be also configured visually, on the Code Editing | C# | Formatting Style | Line Breaks page of ReSharper options Alt+R, O. [resharper_]csharp_keep_user_linebreaks, [resharper_]csharp_keep_existing_arrangement, [resharper_]csharp_keep_existing_linebreaks, [resharper_]keep_user_linebreaks, [resharper_]keep_existing_arrangement, [resharper_]keep_existing_linebreaks ... This option (similarly to the Editorconfig's 'max_line_length') defines the desired maximum number of characters in each line.
🌐
DEV Community
dev.to › buinauskas › maximum-line-length-in-your-code-2ia4
Maximum line length in your code - DEV Community
March 29, 2018 - Until now I've always tried to stick to 80 characters per line and it worked just fine in plain ol'...
🌐
GitHub
github.com › DotNetAnalyzers › StyleCopAnalyzers › issues › 1808
Rule proposal: Line Length · Issue #1808 · DotNetAnalyzers/StyleCopAnalyzers
November 22, 2015 - Each line of code must be no more than 140 characters long. This length was chosen to allow printing of code using a Consolas 10 point typeface, using the landscape printing orientation on Letter (8 ½" x11") or A4 paper.
Author: DotNetAnalyzers
🌐
GitHub
github.com › OmniSharp › omnisharp-vscode › issues › 4248
Support max_line_length from editor config · Issue #4248 · dotnet/vscode-csharp
November 26, 2020 - Currently this is not enforced in any way. max_line_length property determines line length and should enforce wrapping lines that exceed max_line_length characters.
Author: dotnet
🌐
Reddit
reddit.com › r/csharp › is there an all-in-one code style solution yet?
r/csharp on Reddit: Is there an all-in-one code style solution yet?
February 11, 2023 -

Being spoiled by the ease of use of formatters like black/gofmt/clang-format I wonder if there's finally a solution for C# yet? dotnet format seems ok but doesn't do line breaking or spurious empty line removal (please correct me if I'm wrong)? CSharpier does do the latter but doesn't do things like converting single-line properties/functions to expression bodies as dotnet format does nor enforcing naming rules, ordering of things within a class? And clang-format/uncrustify/astyle just don't seem to know C# enough to even get close.

How do others do this? Some magic tool I don't know about? Just live with it like in the old days?

Top answer
1 of 6
24
I think for the most part the community uses Visual Studio or Rider and lets them format the code as they work. You see formatters in the open-source world more because a lot of languages like Python spawned around text editors, not IDEs, so a lot of people from a lot of backgrounds with a lot of preferences contribute and it's good to have a tool enforcing formatting. In the .NET world, you can make a .editorconfig and the people not using an IDE are the weird ones. I feel like a lot of people come to C# from other languages and waste a lot of time getting started because they go on a quest to find a formatter/linter and can't figure out why nobody answers the question. Your code formatting is not a deliverable!
2 of 6
12
Rider/Resharper have the most comprehensive code cleanup I've ever seen for any language. It can enforce pretty much any code style rule one can think of (not just small things like spaces around operators) over whole solution. Specifically from what you asked: Will enforce line breaking wherever you want it (for example I've configured it to enforce line breaks in each chained LINQ-style method calls if at least one line break was introduced in the chain by developer). Will convert one-liners to expression bodies if configured. Will not fix naming automatically as part of cleanup, but there is separate "Fix naming in file/project/solution" command. Will also try to find non-code usages and ask to rename them as well (i.e. hardcoded strings of the same name). Has quite powerful file/type ordering rules, so your fields/properties/methods/etc will be ordered exactly how you want. I personally just copied StyleCop rules regarding ordering. Didn't use it myself, but if I understand correctly, all this can be used separately from IDE for free as CLI tool .