You must Sign In to post a response.
  • Category: Career Guidance

    what is destructor function ? why it is used in class ?

    Are you looking for a information on destructor function ? want to know its usage ? then read this thread to know more about it

    why is a destructor function required in a class.what is the reason
  • #725487
    Hai Mounika,
    Destructor is a special type of function which is used to release the memory of the page/form after the page.form is displayed or rendered to the window.
    It is special type of function because this is the function which doesn't have any return type.
    in C#, the syntax for the Desctructor is:

    public ~ClassName()

    Destructor can't be overridden.
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #725536
    Destructor is used to desctruct the instances of a class. In c# we might not be sure when the destructor will execute because it is determined by the Garbage Collector. So it is the Garbage collector which checks if any object is not in the use in program, if it finds any it destructs it and reclaims for the memory. But still we can call the destructor implicitly by use of Object.Finalize method.



  • #726085

    Destructors are used to cleanup if the class is holding resources for long time.It is automatically called by the garbage Collector in C#.In Destructors we can put code to release resources.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.