How do you add a destructor to a class made in C # to destroy it when it is no longer needed?
Read this one .
But you might consider introducing IDisposable, which usually offers a more elegant solution. Go here for more information.
Do not use a destructor. Use Dispose () and Finalize () instead.
This is a good article on this topic: When and how to use Dispose and Shut Down in C #
, . , , Interop/p/invoke.
class Person { // Destructor ~Person() { // Cleanup resources that the object used here. } }
! # .
:
class Person { // Destructor ~Person() { // Clean-up resources that the object used here. } }
class Person { // Destructor public override void Finalize() { // your clean up base.Finalize(); } }
, Finalize. .NET Finalize , , Finalize 2 GC, .
++, , , GC .
class Car { ~Car() // destructor { // cleanup statements... } }
MSDN.
~ className() {}
Source: https://habr.com/ru/post/1702350/More articles:Are there any mocking libraries that support the .NET Compact Framework - .netPolygon Filling: Fulfilling the Winding Rule Against the Even Rule - performanceFileNotFoundException error when a file exists - javaASP.NET MVC RC - creating a custom MVC control with codebehind - asp.net-mvcExplicit API methods and generic parameter-based API methods - apiHow to intercept response and xml request during web service call? - javaUsing JNDI to get user group name in Windows XP - javaIQueryable setup - .netHow to handle obsolete connections? - javaWhy is my Access database not updating when I read it from another process? - ms-accessAll Articles