Just wondering if this would be an acceptable way of terminating an object from within itself? Since
this = null;
is not possible. I usually just set a bool called disposed or something and throw an exception if the object is accessed after I terminate it. But then this occurred to me and I thought it might be a cleaner solution but it seems a bit hacky so I wanted a second opinion. Should I stick with setting a bool or go with this. This would also allow the garbage collector to clean up my object too.
public class A
{
public A()
{
}
public void Method()
{
try
{
//Do Something.
}
catch
{
//If it fails destroy the object
Destroy(this);
}
}
private static void Destroy(A a)
{
a = null;
}
}