What are finalizers in C#?

CsharpProgrammingServer Side Programming

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.

Published on 13-Aug-2018 06:34:14