Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Destructor Syntax in C# and C++ 

You cannot call or override the Object.Finalize method from the C# or C++ programming languages. C# uses destructors as the mechanism for writing finalization code, as described in Destructors (C# Programming Guide).

In C++, destructor syntax is used to implement the Dispose method. C++ provides its own syntax for implementing the Finalize method, as described in Destructors and Finalizers in Visual C++.

NoteNote

Prior to version 2.0 of the .NET Framework, C++ used destructor syntax to implement the Finalize method, as C# does, and did not have special syntax for implementing the Dispose method. To compile C++ code that uses the earlier syntax, use the /clr:oldSyntax compiler option.

Although they look similar, the C# and C++ destructors do not have the same semantics as unmanaged C++ destructors. Managed code does not support anything similar to C++ destructor semantics.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft