So I have this annoying issue with Visual Studio (when working with C#), I've been digging around in the C# formatting options, general VS options and on google and MSDN but can't really find a fix for this - I'm assuming there's just a checkbox somewhere and I've just overlooked it. Here it is:
所以我在Visual Studio中遇到这个恼人的问题(使用C#时),我一直在挖掘C#格式化选项,一般VS选项以及谷歌和MSDN,但无法真正找到解决方案 - 我是假设某个地方只有一个复选框,我只是忽略了它。这里是:
I like to format my code like this:
我想像这样格式化我的代码:
Type var2 = new Type();
Type someVar = new Type();
But visual studio insists on formatting it like this, whenever the automatic format feature is applied:
但只要应用了自动格式功能,visual studio就会坚持按照这样的格式进行格式化:
Type var2 = new Type();
Type someVar = new Type();
Where do I turn this annoying feature off?
我在哪里关闭这个恼人的功能?
4 个解决方案
#1
In the Formatting Options, In the Spacing section:
在格式选项中,在间距部分中:
there is an option called 'Ignore spaces in declaration statements'. Check that option, and VS.NET will not re-format the declarations that you make.
有一个名为“忽略声明中的空格”的选项。检查该选项,VS.NET不会重新格式化您所做的声明。
So, this should work:
所以,这应该工作:
int i = 5;
int melp = 4;
But, when you do this, VS.NET will still reformat your code:
但是,当你这样做时,VS.NET仍然会重新格式化你的代码:
int i;
int melp;
i = 5;
melp = 4;
will become:
int i;
int melp;
i = 5;
melp = 4;
So, it is really only in declaration statements that VS.NET will ignore the extra spacing you provide.
因此,只有在声明语句中,VS.NET才会忽略您提供的额外间距。
#2
Tools|Options|C#|Formatting
I. Ignore spaces in declaration statements <<-- check this
I.忽略声明中的空格<< - 检查一下
AND
II. Set spacing for operators
Insert space...
Ignore spaces ... <<-- check this
II。为运算符设置间距插入空格...忽略空格... << - 选中此项
#3
Tools -> options -> Text Editor -> C# -> Tabs -> "Keep Tabs"
工具 - >选项 - >文本编辑器 - > C# - >选项卡 - >“保持选项卡”
#4
Look at Tools|Options|C#|Formatting
查看工具|选项| C#|格式
#1
In the Formatting Options, In the Spacing section:
在格式选项中,在间距部分中:
there is an option called 'Ignore spaces in declaration statements'. Check that option, and VS.NET will not re-format the declarations that you make.
有一个名为“忽略声明中的空格”的选项。检查该选项,VS.NET不会重新格式化您所做的声明。
So, this should work:
所以,这应该工作:
int i = 5;
int melp = 4;
But, when you do this, VS.NET will still reformat your code:
但是,当你这样做时,VS.NET仍然会重新格式化你的代码:
int i;
int melp;
i = 5;
melp = 4;
will become:
int i;
int melp;
i = 5;
melp = 4;
So, it is really only in declaration statements that VS.NET will ignore the extra spacing you provide.
因此,只有在声明语句中,VS.NET才会忽略您提供的额外间距。
#2
Tools|Options|C#|Formatting
I. Ignore spaces in declaration statements <<-- check this
I.忽略声明中的空格<< - 检查一下
AND
II. Set spacing for operators
Insert space...
Ignore spaces ... <<-- check this
II。为运算符设置间距插入空格...忽略空格... << - 选中此项
#3
Tools -> options -> Text Editor -> C# -> Tabs -> "Keep Tabs"
工具 - >选项 - >文本编辑器 - > C# - >选项卡 - >“保持选项卡”
#4
Look at Tools|Options|C#|Formatting
查看工具|选项| C#|格式