Introduction
In this blog, we will learn the difference between the "finalise" and "finally" methods in .NET. This question is often asked in interview questions.
Difference between finalise and finally methods
First, there is no relation between the finalise method and the finally method. However, I don't understand why some interviewers ask this question. I think they do it simply because these names are similar.
The Finalise method is used for garbage collection. We already know this; it will automatically run by garbage. But, before destroying any object, this method is called by the garbage collector.
Finally is the part of the exception handling, as you can see in below figure-1.
figure-1
Finally has nothing to do with the garbage collection. It is a part of the exception handling - the try, catch and finally with which you may be familiar. This method is used to execute the code, irrespective of whether an exception occurred or not. If you want to go into the details of the finally method, you can check out the below mentioned articles:
Conclusion
Here, we have learned the difference between the finalise and finally methods.
If you have any queries or suggestions, please leave your questions and thoughts in the comment section below. Follow C# Corner to learn more new and amazing things about .NET or to explore more technologies.
Thanks for reading, and I hope you like it.