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.