Refactor instance declaration from try block to above try block in a method

Posted by dotnetdev on Stack Overflow See other posts from Stack Overflow or by dotnetdev
Published on 2010-03-26T15:18:36Z Indexed on 2010/03/26 15:23 UTC
Read the original article Hit count: 397

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

© Stack Overflow or respective owner

Related posts about refactoring

Related posts about visual-studio-2008