Predefined Live Templates
ReSharper provides a number of predefined Live Templates covering some of the most commonly used standard code fragments. This section describes each of these templates in detail. For details on how to invoke Live Templates, see Using Live Templates.
All predefined templates and corresponding abbreviations are described below, divided into several groups.
Plain
Templates in this group are very simple: they expand to short static C# code fragments. Example:
- To declare a constant with
public const int, type pci:

- Press Tab. The following code fragment will expand with the caret positioned at the next reasonable input point:
| Abbreviation |
Full code after expansion |
Details |
| pci |
public const int
|
|
| pcs |
public const string |
|
| psr |
public static readonly |
|
| thr |
throw new |
|
| asrt |
System.Diagnostics.Debug.Assert(); |
After expansion the caret is positioned between the parentheses so that you can start writing the assertion. |
| psvm |
public static void Main(string[] args)
{
} |
After expansion the caret is positioned between the braces so that you can start writing the function body. |
Iterations
Templates in this group are used for iterating over various containers. Since these templates are parametrized, you will need to fill in some parameters (variables) after the template is expanded. These input fields routinely include:
- loop index variable;
- the number of iterations;
- the container instance.
To help you complete the necessary input fields, ReSharper will suggest a list of choices. They include names for variables, instances of arrays, lists, etc which are available in the scope and so on. Please see this pictorial for a graphic illustration of the process.
Click a template abbreviation in the list below to go to its description:
-
| Abbreviation |
| Specification |
| loop |
Purpose
Quickly creates a generic-purpose for loop.
Typical use case

After expansion

Parameters you are asked to complete
i - loop index variable
UPPER - number of iterations
After parameters are specified, the caret is placed so that you can write the loop body.
|
| itar |
Purpose
Generates a for loop for iterating over an array. Includes a customizable statement in the loop body with a variable holding container elements.
Typical use case

After expansion

Parameters you are asked to complete
i - iterator variable
array - array instance to iterate over (in the example above, arrayOfStrings has been automatically suggested by ReSharper because it's available in the scope)
object - type to cast the array elements (in the example above, a type is usually suggested by ReSharper based on the array type)
o - variable to hold the current array element (ReSharper makes some suggestions based on the type name, for example, s for string)
|
-
After parameters are specified, the caret is placed so that you can continue writing the loop body. For a more detailed illustration, refer to this pictorial.
-
| ritar |
Purpose
Generates a for loop for iterating over an array in reverse order. Includes a customizable statement in the loop body with a variable holding container elements.
Typical use case

After expansion

Parameters you are asked to complete
i - iterator variable
array - array instance to iterate over (in the example above, arrayOfStrings has been automatically suggested by ReSharper because it's available in the scope)
object - type to cast the array elements (in the example above, string type is usually suggested by ReSharper based on the type of the array)
o - variable to hold the current array element (ReSharper makes some suggestions based on the type name, for example, s for string)
After parameters are specified, the caret is placed so that you can continue writing the loop body.
|
| ital |
Purpose
Generates a for loop which iterates over an instance of System.Collections.ArrayList. Includes a customizable statement in the loop body with a variable holding container elements.
Typical use case

After expansion

Parameters you are asked to complete
i - iterator variable
array - instance of ArrayList to iterate over (in the example above, myList has been automatically suggested by ReSharper)
object - type to cast the container elements to
o - variable to hold the current list element (ReSharper makes some suggestions based on the name of the array)
After parameters are specified, the caret is placed so that you can continue writing the loop body.
|
| itli |
Purpose
Generates a for loop which iterates over an instance of System.Collections.IList. Includes a customizable statement in the loop body with a variable holding container elements.
Typical use case

After expansion

Parameters you are asked to complete
array - instance of ArrayList to iterate over (in the example above, myList has been automatically suggested by ReSharper)
object - type to cast the container elements to
o - variable to hold the current list element (ReSharper makes some suggestions based on the name of the array)
After parameters are specified, the caret is placed so that you can continue writing the loop body.
|
| itdic |
Purpose
Generates a foreach block which iterates over an instance of System.Collections.IDictionary. Includes two customizable statements in the loop body with two variables holding the key and the value of the dictionary element, respectively.
Typical use case

After expansion

Parameters you are asked to complete
entry - iterator variable
dictionary - dictionary instance to iterate over (in the example above, myDict has been automatically suggested by ReSharper because it is available in the scope)
object - type to cast the dictionary keys to
o - variable to hold the keys of dictionary elements
value - variable to hold the values of dictionary elements
After parameters are specified, the caret is placed so that you can continue writing the loop body.
|
| itdg |
Purpose
Generates a foreach block which iterates over an instance of System.Collections.IDictionary. Includes two customizable statements in the loop body with two variables holding the key and the value of the dictionary element, respectively.
Typical use case

After expansion

Parameters you are asked to complete
entry - iterator variable
dictionary - dictionary instance to iterate over (in the example above, myDict has been automatically suggested by ReSharper because it is available in the scope)
object - type to cast the dictionary keys to
o - variable to hold the keys of dictionary elements
value - variable to hold the values of dictionary elements
After parameters are specified, the caret is placed so that you can continue writing the loop body.
|
| foreach |
Purpose
Generates a foreach block which iterates over an instance of System.Collections.IEnumerable.
Typical use case

After expansion

Parameters you are asked to complete
collection - instance of IEnumerable to iterate over (in the example above, ReSharper has suggested the list of all instances available in the scope)
object - type to cast the array elements to
o - iterator variable (in the example above, array has been suggested by ReSharper based on the type name)
After parameters are specified, the caret is placed so that you can continue writing the loop body.
|
Output
Output templates expand to Console.Out.WriteLine statements. Click a template abbreviation in the list below to go to its description:
| Abbreviation |
Specification |
| out |
Purpose
Creates a simple WriteLine statement for outputting a string to the system console.
Typical use case

After expansion

The caret is placed between the quotation marks so that you can start typing the output message.
|
| outv |
Purpose
Outputs the value of a variable defined in the current scope.
Typical use case

After expansion

ReSharper automatically suggests a list of all variables in the current scope and, by default, selects the most recently declared one. The descriptive text string ("s = " in the example above) is automatically synchronized with the name of the selected variable.
|
Other
Click a template abbreviation in the list below to go to its description:
-
-
| Abbreviation |
Specification |
| ear |
Purpose
Generates a code fragment that creates an empty array.
Typical use case

After expansion

Parameters you are asked to complete
TYPE - type of array elements
types - name of array variable (ReSharper comes up with some suggestions based on the TYPE chosen, for example, ints for int type)
|
| toar |
Purpose
Generates a code fragment that copies the elements of System.Collections.ArrayList to an array by using the ToArray() method.
Typical use case

After expansion

Parameters you are asked to complete
ArrayList - instance of ArrayList sdfsdf (ReSharper suggests a list of all instances available in the scope, as in the example above)
type - name of array variable (ReSharper guesses the returned element type, as in the example above (char))
Tip This template is most efficiently used where the required element type can be determined from the context.
After parameters are specified, the caret is placed at the end of the statement.
|
| sfc |
Purpose
Generates a code construct to safely cast variables.
Typical use case

After expansion

Parameters you are asked to complete
TYPE - type to cast to (ReSharper suggests a list of all instances available in the scope, as in the example above)
type - name of new variable to cast to (ReSharper comes up with some suggestions based on the TYPE chosen)
o - name of variable to cast to TYPE (ReSharper makes some suggestions from the list of members available in the scope)
|
-
After parameters are specified, the caret is placed between the braces so that you can write the body of the if statement.
-
See Also
Using Live Templates | Managing and Sharing Live Templates