In C# you can make sure Dispose is always called for an object, if the object is created within using statment
for e.g
using(Font onefont = new Font("Courier")
{
//do something
}
When the using blocks end, Dispose on the Font will be called automatically. Even if there is exception while creating the object or within the using block, Dispose method will still be called. An implicit finallt block is created for you.
for e.g
using(Font onefont = new Font("Courier")
{
//do something
}
When the using blocks end, Dispose on the Font will be called automatically. Even if there is exception while creating the object or within the using block, Dispose method will still be called. An implicit finallt block is created for you.
Comments