C#

 1.Constructor:

A constructor is a special method with the same name as the class that is automatically called when an instance (object) of the class is created.

It is used to initialize objects and  set initial values for fields.

2.Destructor:

  • A destructor is a special method named with the class name prefixed by a tilde (~). For example, if the class is MyClass, the destructor would be ~MyClass.
  • Destructors are called automatically by the garbage collector when an object is about to be destroyed and its memory is being reclaimed.
  • destructors are not commonly used because the garbage collector automatically manages memory and releases resources


Comments