Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 如何在VisualStudio中修复注释在}else{之前的缩进?_Visual Studio 2010_Comments_Text Editor_Indentation - Fatal编程技术网

Visual studio 2010 如何在VisualStudio中修复注释在}else{之前的缩进?

Visual studio 2010 如何在VisualStudio中修复注释在}else{之前的缩进?,visual-studio-2010,comments,text-editor,indentation,Visual Studio 2010,Comments,Text Editor,Indentation,下面是一个典型的例子: // Testing expression if (expression) { method(); // All other options } else { otherMethod(); } 我认为,第二条评论被VisualStudio编辑器错误地(太天真地)制成了表格,因为它假定它是针对第一个块的 目前,我的缩进设置为Smart,如果代码包含在一对新的括号内,将其设置为Block将不允许重新构造(自动缩进) 如何纠正这种行为,使块末尾的注释根据下

下面是一个典型的例子:

// Testing expression
if (expression) {

  method();

  // All other options
} else {

  otherMethod();

}
我认为,第二条评论被VisualStudio编辑器错误地(太天真地)制成了表格,因为它假定它是针对第一个块的

目前,我的缩进设置为Smart,如果代码包含在一对新的括号内,将其设置为Block将不允许重新构造(自动缩进)


如何纠正这种行为,使块末尾的注释根据下面的块缩进?

您需要了解哪些内容在范围内,哪些内容不在范围内。括号内的所有内容都在相同的范围内,因此具有相同的缩进级别。即编辑器正按照其设计的方式进行操作。如果您希望要使注释具有相同的缩进级别,请将其放在相同的范围内。下面是一个示例,其中注释与else具有相同的缩进级别,因为它们共享相同的范围。我更改了括号的位置,以遵循代码中使用的更标准的格式:

//First option: if (expression) { method(); } // All other options (This is the same scope as if above and else below) else { otherMethod(); } //第一种选择: if(表达式) { 方法(); } //所有其他选项(与上面和下面的选项范围相同) 其他的 { 其他方法(); }
删除额外的标签?顺便说一句-在我看来没有错。注释开始于
else
的正上方。它认为注释位于前一个代码块中,因为它位于
if
的右大括号内。依我看,它工作正常,因为它假设您使用C标准代码样式。您认为它的标签错误是什么意思?它是在与
method()
call相同的选项卡距离上突出显示代码块,然后编辑菜单>高级>格式选择争论样式没有什么意义,但该注释实际上属于else{}主体。我认为IDE团队也是如此。您有删除键来强制执行自己的样式。