3 ms·
..huh? But either way, should you ever be annoyed by K&R again next time you work with C#, you can trivially change it by setting csharp_new_line_before_open_br
by neonsunset 3y ago
..huh? But either way, should you ever be annoyed by K&R again next time you work with C#, you can trivially change it by setting csharp_new_line_before_open_brace = none in .editorconfig and running dotnet-format tool against solution files.
- kbolino 3y agoK&R doesn't just mean the opening brace isn't on its own line, it also means single-line blocks have no braces at all. Always using braces but not putting the opening one on its own line is 1TBS (not the best name, but I don't know what else it's called).
- neonsunset 3y agoYou can omit them too (at the risk of legibility in some conditions). All these are configurable (and not enforced by default but you can definitely do so with .editorconfig). It is also fairly popular in C# to use expression-bodied members where they have just a single expression/statement e.g. class Test { public int Property => 42; public void Method() => Console.WriteLine(42); }
- kbolino 3y agoYeah, I think OP's point is that nobody should be omitting braces in this day and age. Maybe there's a setting to force the use of braces too.