C# 2008
I have been working on this for a while now, and I am still confused about the use of finalize and dispose methods in code. My questions are below:
using(NoGateway objNoGateway = new NoGateway())
is equivalent to
try
{
NoGateway = new NoGateway();
}
finally
{
NoGateway.Dispose();
}
A finalizer is called upon the GC destroying your object. This can be at a totally different time than when you leave your method. The Dispose of IDisposable is called immediately after you leave the using block. Hence the pattern is usually to use using to free ressources immediately after you don't need them anymore.