为什么C#不能像VB.NET那样自动格式化行缩进 [英] Why can't C# automatically format line indentations like VB.NET does

查看:75
本文介绍了为什么C#不能像VB.NET那样自动格式化行缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当我在VB.NET中编写内容时,VS 2017 IDE会自动完美地格式化我的行缩进,我不必在任何时候使用Tab键。


在C#中,当我需要编辑一行代码时,我可能会破坏这样的缩进...

 

 void MyVoid()
{
if(1 == 1)
{
int iThis = 5; //粗俗缩进行
}
}



...,和我必须手动更正缩进或使用Ctrl AKF来修复它。


在VB.NET中,当我跳到任何其他行时,IDE会自动修复它。


为什么C#比VB.NET更难,我可以在某处更改吗?

解决方案

我的朋友,


< p style ="margin-bottom:12pt"> 欢迎来到MSDN论坛。


参考你的描述,我在我的VS中测试过它社区/企业2017,看起来压痕工作正常如你所愿,请检查以下
截图:



通常,代码样式设置在工具>选项...>文本编辑器> C#>代码样式>格式化,您是否尝试自行修改或配置
之前?


我的上述共享屏幕截图是默认设置,您可以转到工具>导入和导出设置...>重置所有设置并保存当前设置,然后
选择'常规'并单击"完成"按钮将VS设置重置为默认设置,然后再次测试示例代码。





最好的问候,


萨拉


When I write something in VB.NET, the VS 2017 IDE automatically formats my line indents perfectly, I don't have to use the tab key at anytime.

In C#, when I needed to edit a line of code, and I perhaps wrecked up the indentation like this...

void MyVoid()
{
    if (1==1)
    {
     int iThis = 5; //line with ugly indentation
    }
}


..., and I have to correct the indentation manually or use Ctrl AKF to fix it.

In VB.NET, the IDE would fix it automatically when I skip to any other line.

Why does C# make it so much harder than VB.NET, and can I change that somewhere?

解决方案

Hi my friend,

Welcome to the MSDN forum.

Refer to your description, I tested it in my VS community/enterprise 2017 and it looks like the indentation works fine as your expected, please check the following screenshot:

Usually, the code style is setting under Tools > Options… > Text Editor > C# > Code Style > Formatting, have you tried to modify or config it by yourself before?

My above shared screenshot is the default setting and you can go to Tools > Import and Export Settings… > Reset all settings and save your current settings, then choose ‘General’ and click ‘Finish’ button to reset the VS settings to the default ones, then test the sample code again.

Best regards,

Sara


这篇关于为什么C#不能像VB.NET那样自动格式化行缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆