if you need an object later, you do not need to use a use block. it is recommended to use it, but in some cases you can use the following structure:
class b = null; try { b = new class(); } catch (Exception) { throw; } finally { if (b != null) { b.Dispose(); b = null; } }
thus b will be located at the end of your method, if exists.
you are also allowed to have a use block inside the block used:
using (Class a=new Class()) { using (Class b=new Class()) { } }
Koryu source share