I am a beginner in C#, I don't know why this isn't working, I just want to set this object to null by calling Dispose()
method.
Why this is not possible?
class MyClass:IDisposable
{
public void Dispose()
{
this = null;
}
}
The purpose of the Dispose
method isn't to clean up that class, but to clean up the disposable dependencies that the class is holding on to so that it can be disposed of normally by the garbage collector.
I'd suggest reading up more on the Dispose
pattern and how to implement it in C#.
A bit of pedantry: The Dispose
method is not a destructor, nor is it a finalizer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With