Refactor instance declaration from try block to above try block in a method
- by dotnetdev
Hi,
Often I find myself coming across code like this:
try
{
StreamWriter strw = new StreamWriter();
}
However, there is no reference to the object outside the scope of the try block. How could I refactor (extract to field in Visual Studio says there is no field or something) the statement in the try block so that it is declared above the try block so I can use it anywhere in the method?
Thanks