I have a small confusion with the IDisposable interface and the using keyword in C# on which classes we could use it.
using (DataSet studentDS = GetMyStudentDS())
{
// here comes some code
}
I found that Classes inherited from DataSet class are not finalized by the garbage collector, if so is it a good practice to put that in the using block so that it is done manually once its job is done. could someone brief it for the benefit of all. Thanks.
Yes it is. As DataSet implement IDisposible interface. DataSet extends MarshalByValueComponent class. MarshalByValueComponent class implements IDisposable.
Any derived type will also have IDisposable implemented. If it does not explicitly implements (in other words override IDisposable.Dispose), base method (DataSet.Dispose) will be called.
Regarding the Finalizer, that is a separate concept to make sure that unmanaged resources are cleaned up even if developer fails to call the Dispose method (or forgets using block).