用大括号包装多个语句 [英] Wrapping multiple statements in braces

查看:141
本文介绍了用大括号包装多个语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2010中是否存在键盘快捷键(我也在使用ReSharper 6.1),该快捷键使我可以使用花括号将选定的文本块括起来?我尝试了与...一起环绕" (Ctrl + K,Ctrl + S),但是我没有在列表中看到选择花括号作为周围元素的选项.常见的用例是,我将有一个if语句,如下所示:

Is there a keyboard shortcut in Visual Studio 2010 (I'm using ReSharper 6.1 also) that will allow me to surround a selected block of text with curly braces? I tried "Surround With..." (Ctrl+K, Ctrl+S), but I didn't see an option in the list to choose curly braces as the surrounding element. The common use case for this is that I'll have an if-statement like the following:

if (conditional)
    statement1;
// the rest of the program

我将意识到,在if语句中还需要执行一些其他任务,并添加它们:

I'll realize that there are some additional tasks that need to be performed inside the if-statement and I add them:

if (conditional)
    statement1;
    statement2;
    statement3;
// the rest of the program

然后,我记得我需要将所有语句都用大括号括起来,并且代码应该看起来像这样:

Then, I remember that I need to wrap all the statements in curly braces and the code should really look like this:

if (conditional)
{
    statement1;
    statement2;
    statement3;
}
// the rest of the program

我想做的只是选择三个语句,然后按快捷键将它们用花括号括起来.我实际上要做的是将光标移动到条件语句后的行首,然后键入{字符,然后删除ReSharper(无益地)自动在{之后立即插入的字符},然后将光标向下移动到末尾最后一段语句的内容,然后输入}以完成该段.

What I'd like to do is just select the three statements and then hit a shortcut key to wrap them in curly braces. What I actually end up doing is moving the cursor to the beginning of the line after the conditional, then typing a { character, then deleting the } character that ReSharper (unhelpfully) automatically inserts immediately after the {, then moving the cursor down to end of the last statement of the block and entering } to complete the block.

推荐答案

选择代码行.

按Ctrl E-U(带有模板的环绕键)(或对于Intelli J,按Ctrl Alt J).

Press Ctrl E-U (Surround with template) (or Ctrl Alt J for Intelli J).

选择选项7:{}.

为我工作.

这篇关于用大括号包装多个语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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