Simple question. What is the difference between class destructor and dispose. Lets say in my class I have a RegistryKey, a COM object and some more things which needs to be disposed when class object is out of scope. I have code which does this, and I have put this both in destructor and dispose method. What is the best thing to use here.
public MyClass : IDisposable
{
public ICOMObject SomeCOMObject;
public RegistryKey registryKey;
MyClass()
{ Initialize things; }
~MyClass()
{
ClearThings();
}
public void Dispose()
{
ClearThings();
}
private void ClearThings()
{
// Clear things.
}
}