[英]Fix indentation of if-else in VS2015
This is how VS2015 indents code (using "Format Document"): 这就是VS2015缩进代码的方式(使用“格式文档”):
void actual()
{
int i = 0;
if (i == 1)
Text = "a";
else
if (i == 0)
Text = "b";
else
Text = "c";
}
Is there a way to fix it to have corresponding if
and else
statements with the same indentation, and indented more than the previous indentation without adding brackets? 有没有一种方法可以解决它,使对应的
if
和else
语句具有相同的缩进,并且比以前的缩进缩进更多而无需添加括号?
EDIT 编辑
I would expect it to be like in previous versions (VS 2010 and 2013): 我希望它与以前的版本(VS 2010和2013)类似:
void expected()
{
int i = 0;
if (i == 1)
Text = "a";
else
if (i == 0)
Text = "b";
else
Text = "c";
}
You have an if
with 3 branches that you are trying to treat as a 2 branch if
with another if
inside it. 你有一个
if
有3个分支,你正试图把一个2分支if
与另一个if
里面。 This doesn't seem to be a formatting problem, but rather a problem with the interpretation of how the branches work. 这似乎不是格式问题,而是分支的工作原理的解释问题。
If you really want it as 2 separate if
s then you would have to write it this way: 如果您真的希望将它作为2个独立的
if
s,那么您将不得不这样编写:
void expected()
{
int i = 0;
if (i == 1)
Text = "a";
else
{
if (i == 0)
Text = "b";
else
Text = "c";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.