What are finalizers in C#?


Finalizers in C# are used to destruct instances of classes. With that, you can also use it to release resources.

Here are some of the key points about Finalizers −

  • Only one finalizer is allowed for a class
  • You cannot inherit or overload Finalizers
  • A finalizer cannot have parameters
  • Finalizers invoke automatically

Finalizers in C# are declared like destructors. Let’s say the class name is Demo, therefore, the following would be our finalizer −

~Demo() {
   //
}

The finalizer declaration is prefixed with a tilde before the class name.

Updated on: 20-Jun-2020

598 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements