Introduce Using Statement
Replaces a disposable object creation statement with the using statement. If the Dispose() method was called explicitly, this refactoring removes it and closes the using body on the line that was holding the Dispose() method. This increases the code readability and ensures that the objects you are using locally are properly disposed of.
Available when the caret is on an object creation statement assuming that the object implements the IDisposable interface.
Place the caret on the IDisposable object creation statement.
The blinking cursor shows the caret's position at which the Refactoring is available.
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- Select Introduce Using Statement from the menu.
After execution, the Refactoring replaces the object creation and disposition statements with the using statement.