Back to Devexpress

Widen Scope

coderushforroslyn-115616-refactoring-assistance-widen-scope.md

latest1.2 KB
Original Source

Widen Scope

  • Aug 03, 2020

Purpose

Moves a variable declaration out of the parent code block, which makes it available in a parent scope.

Availability

Available on a variable declaration within a loop, or a conditional statement.

Usage

  1. Place the caret on a variable declaration.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Widen Scope from the menu.

After execution, the Refactoring moves the variable declaration out of the current scope.

csharp
int i = 0;
for (; i < 10; i++) {
    // ...
}
// 'i' exists here
vb
Dim i As Integer
For i = 0 To 9
    ' ...
Next i
' 'i' exists here

See Also

Widen Scope (Promote to Field)

Remove Type Qualifier

Promote to Parameter

Inline Temp

Inline Method and Delete