Michal B.
Michal B.

Reputation: 5719

What's VS2010 shortcut for surrounding the line in a if block

Let's assume I have a following line

myObject.SomeStatement();

My cursor is at the end of the line.
What's the keboard shortcut to put an if statement around it and obtain:

if ()
{
    myObject.SomeStatement();
}

What's the keboard shortcut to put a for loop around it and obtain:

for (int i = 0; i<length; ++i)
{
    myObject.SomeStatement();
}

Upvotes: 2

Views: 254

Answers (3)

utsikko
utsikko

Reputation: 1545

In addition, please check also this reference page Visual Studio 2010 Keybinding Posters, with details on shortcuts for all VS2010 languages.

Upvotes: 2

Cristian Lupascu
Cristian Lupascu

Reputation: 40576

I use Edit.SurroundWith (CTRL+K, CTRL+S) and then select if from the popup list

You can surround with a for in a similar manner.

There are actually many surround templates available - I also use the try and tryf templates quite often (perhaps a sign that I'm doing it wrong ☺).

Upvotes: 4

Mithrandir
Mithrandir

Reputation: 25397

As far as i know the behaviour you want isn't quite there, but something close, i think. Take your statement:

myObject.SomeStatement();

and select the line, e.g. by double clicking, and press CTRL+K, CTRL+S, then select the "snippet" you want to apply.

Upvotes: 1

Related Questions