如何在C# Visual Studio if-statements中删除换行符

roqulrg3  于 2023-11-21  发布在  C#
关注(0)|答案(2)|浏览(212)

当我打字

  1. if (something) { *press Enter*

字符串
Visual Studio会自动将{移动到下一行。我试图通过配置禁用它,但发现除了此选项之外的其他选项。
我基本上是想

  1. if (true)
  2. {
  3. int m = 3;
  4. }


变成了这样

  1. if (true) {
  2. int m = 3;
  3. }


怎么做?

3zwjbxry

3zwjbxry1#

通过在Visual Studio中取消选择“将左大括号放置在类型的新行上”选项,可以将左大括号更改为显示在同一行上。
工具>选项对话框>文本编辑器> C# >代码样式>样式


的数据
参考:https://learn.microsoft.com/en-us/visualstudio/ide/reference/options-text-editor-csharp-formatting?view=vs-2022

rmbxnbpk

rmbxnbpk2#

Tools菜单中选择Options...
Text Editor> C#> Code Style> Formatting> New Lines下面有很多选项,这些选项将有助于Kernighan &里奇(K&R)支撑样式。对于问题中的代码,相关设置是Place open brace on new line for control blocks;但您可能也想更改其他几个选项。
如果你使用.editorconfig来管理你的样式,你需要的设置是csharp_new_line_before_open_brace,值为“none”。

相关问题