Predefined 'Surround With' Templates

ReSharper comes with a number of predefined 'Surround With' Templates. You can use them as is or customize them to best suit your programming needs and your programming style (for details see Managing and Sharing 'Surround With' Templates).

 

Some templates are parametrized, requiring that you fill in some parameters (variables) after the template code is inserted. Please see this pictorial for a graphic illustration of the process.
 
Click a template's name in the list below to go to its description:
 
Name Specification
if Allows to place the selected code inside a conditional execution block. Consider the following code:

Selecting the code, pressing Ctrl + Alt + J and choosing if template yields:

The caret is positioned so that you can immediately start typing the logical condition providing execution of the surrounded code.

while Places the selected code inside a while loop. The behavior mirrors that of if template with straightforward substitutions of while in place of if.
for Places the selected code inside a for loop. The behavior mirrors that of if template with straightforward substitutions of for in place of if.
do..while Places the selected code inside a do..while loop. Surrounding the same code example as in the description of if template yields:

lock Places the selected code inside a mutually exclusive execution block (C# lock statement). The behavior mirrors that of if template with straightforward substitutions of lock in place of if.
#region Marks the selected code as a C# region. Places the caret so that you can immediately start typing a preprocessor message for the new region. Surrounding the same code example as in the description of if template yields:

{} Converts the selected code into a C# compound statement by surrounding it with curly braces {}.
try..catch Places the selected code into a try..catch block. See detailed example here.
try..finally

Places the selected code into a try..finally block. The caret is placed inside the finally block. Surrounding the same code example as in the description of if template yields:

cast Consider the following code example:

Clearly, the variable myObject should be cast to ArrayList class. In order to achieve this, in the editor select the expression to be cast (in this case just the myObject variable, but the expression may be as complex as you like), press Ctrl + Alt + J, and finally choose cast template. The code is transformed as follows:

The caret is conveniently positioned so that you can immediately start typing the desired type name.

using
String.Format

 

See Also

Using 'Surround With' Templates | Managing and Sharing 'Surround With' Templates