在使用C#的Visual Studio中(2010年和2012年都会出现这种情况),如果我在else
语句之前输入新行,我会得到一个奇怪的自动缩进:
if (condition1)
{
DoSomething();
} // press Enter here, after the brace
// auto indents to here
// Helpful comment here about condition2, but awkwardly auto-indented
else if (condition2)
{
DoSomethingElse();
}
直观地说,我希望它只会自动缩进到与if
/ else
相同的列,但它会进一步缩进一个列。
我知道无论如何将其他代码放在这两个块之间是违法的,但我仍然想在那里发表评论。有谁知道为什么会发生这种情况或如何解决它?每当我尝试评论else
块时,必须按下退格键4次是非常奇怪和恼人的。
我知道有人会说“只是将评论放在else
/ if
区块内”,但我对这种现象的实际解释/解决方案感兴趣;此外,对我来说,解释代码发生在两行之前是没有意义的。
我也知道有人会说“只是将评论与else
/ if
块放在同一行”,但是将评论和代码放在同一行上对我来说似乎很难过。 / p>
答案 0 :(得分:2)
我刚在Visual Studio 2012中试过这个:
实际上,当您撰写评论时,它似乎没有正确缩进。
但按 CTRL + E , CTRL + D 后,所有内容都会自动缩进(在我的中)意见):
if (condition)
{
}
// comment line
// another one
else if (condition)
{
}