What is the difference, if there is one, between a destructor and a Finalize method in a class?
I recently discovered that Visual Studio 2008 considers a destructor synonymous with a Finalize method, meaning that Visual Studio won't let you simultaneously define both methods in a class.
For example, the following code fragment:
class TestFinalize
{
~TestFinalize()
{
Finalize();
}
public bool Finalize()
{
return true;
}
}
Gives the following error on the call to Finalize in the destructor:
The call is ambiguous between the following methods or properties:
'TestFinalize.~TestFinalize()' and 'TestFinalize.Finalize()'
And if the call to Finalize is commented out, it gives the following error:
Type 'ManagementConcepts.Service.TestFinalize' already defines a member called
'Finalize' with the same parameter types
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…