Consolidate Using Statements
In This Article
Consolidates Using statements into a single statement.
#Availability
Available from the context menu or via shortcuts:
- when the cursor is on a Using statement, provided that there are more Using statements that create instances of the same class.
#Notes
- This refactoring is the functional opposite of Split Using Statement.
#Examples
string toString = string.Empty;
│using (Pen p1 = new Pen(Color.Black))
{
toString += p1.ToString();
}
using (Pen p2 = new Pen(Color.Black))
{
toString += p2.ToString();
}
Dim toString As String = String.Empty
│Using p As Pen = New Pen(Color.Black)
toString += p.ToString()
End Using
Using p1 As Pen = New Pen(Color.Black)
toString += p1.ToString()
End Using
Result:
string toString = string.Empty;
│using (Pen p1 = new Pen(Color.Black), p2 = new Pen(Color.Black))
{
toString += p1.ToString();
toString += p2.ToString();
}
Dim toString As String = String.Empty
│Using p As Pen = New Pen(Color.Black), p1 As Pen = New Pen(Color.Black)
toString += p.ToString()
toString += p1.ToString()
End Using