ReSharper Web Help

ReSharper | Live Templates | Live Templates | Predefined Templates | VB.NET | Iteration

VB.NET

Iteration

Templates in this group are used for iterating over various containers. Since these templates are parameterized, you will need to fill in some parameters (variables) after the template is expanded. These input fields normally include:

  • Loop index variable
  • Number of iterations
  • Container instance

To help you complete the necessary input fields, ReSharper suggests a list of choices. They include names of variables, instances of arrays, lists available in scope etc.

Template name Description
for

Go to top

Purpose
Generates a For loop which iterates until its loop index variable reaches a specified maximum value.

For $VAR$ As Integer = 0 To $MAX$
    $END$
Next

Before expansion
for (before)
After expansion
for (after)

Parameters

  • VAR - name of index variable.
  • MAX - maximum value of index variable.
  • END - empty loop body to be filled by user.
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

foreach

Go to top

Purpose
Generates a For Each block which iterates over an instance of System.Collections.IEnumerable.

For Each $VAR$ As $TYPE$ In $COL$
    $END$
Next

Before expansion
foreach (before)
After expansion
foreach (after)

Parameters

  • VAR - iterator variable.
  • TYPE - type to cast the array elements to.
  • COL - instance of IEnumerable to iterate over.
  • END - empty loop body to be filled by user.
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

itar

Go to top

Purpose
Generates a For loop for iterating over an array.

For $VAR$ As Integer = 0 To $ARRAY$.Length - 1
    Dim $ELEMENT$ As $TYPE$ = $ARRAY$($VAR$)
    $END$
Next

Before expansion
itar (before)
After expansion
itar (after)

Parameters

  • VAR - index variable.
  • ARRAY - array to iterate over.
  • ELEMENT - variable to store array items.
  • TYPE - type of variable used to store array items.
  • END - empty loop body to be filled by user.
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

itdg

Go to top

Purpose
Generates a For Each block which iterates over a System.Collections.IDictionary collection. Includes two customizable statements in the loop body with two variables holding the key and the value of a dictionary element.

For Each $ITER$ As $ITERTYPE$ In $DIC$
    Dim $KEY$ As $KEYTYPE$ = $ITER$.Key
    Dim $VALUE$ As $VALUETYPE$ = $ITER$.Value
    $END$
Next

Before expansion
itdg (before)
After expansion
itdg (after)

Parameters

  • ITER - iterator variable.
  • ITERTYPE - type of iterator variable.
  • DIC - instance ofSystem.Collections.IDictionary.
  • KEY - name of variable used to store the key part of the key-value pair.
  • KEYTYPE - type of variable used to store the key part of the key-value pair.
  • VALUE - name of variable used to store the value part of the key-value pair.
  • VALUETYPE - type of variable used to store the value part of the key-value pair.
  • END - empty loop body to be filled by user.
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

itli

Go to top

Purpose
Generates a For loop which iterates over an instance of System.Collections.IList.

For $INDEX$ As Integer = 0 To $LIST$.Count - 1
    Dim $ELEM$ As $TYPE$ = $LIST$($INDEX$)
    $END$
Next

Before expansion
itli (before)
After expansion
itli (after)

Parameters

  • INDEX - name of loop index variable.
  • LIST - instance ofSystem.Collections.IList.
  • ELEM - name of variable used to store an System.Collections.IList item.
  • TYPE - type of variable used to store an System.Collections.IList item.
  • END - empty loop body to be filled by user.
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

ritar

Go to top

Purpose
Generates a For loop for iterating over an array in reverse order.

For $VAR$ As Integer = $ARR$.Length - 1 To 0 Step -1
    Dim $ELEM$ As $TYPE$ = $ARR$($VAR$)
    $END$
Next

Before expansion
ritar (before)
After expansion
ritar (after)

Parameters

  • VAR - index variable.
  • ARR - array to iterate over.
  • ELEM - variable used to store array items.
  • TYPE - type of variable used to store array items.
  • END - empty loop body to be filled by user.
After you specify the parameters, the caret is positioned so that you can continue coding the loop body.

See Also

Reference