What Is The Difference Between Finalise and Finally Methods

This blog will explain the distinction between the “finalise” and “finally” methods in.NET. This question is frequently asked in job interviews.

Finalise and Finally

First, there is no connection between the finalise and finally methods. However, I’m not sure why some interviewers pose this question. I believe they do that because the names are similar.

The Finalise procedure is used to gather waste. We already know this; it will be run by garbage. The trash collector, however, calls this procedure before deleting any object.

try
{
SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=master; Integrated Security=True") ;
//some logic
//error occured
}
catch (ExceptionName Exp)
{
//Error handled
}
finally
{
//connection close
}

Finally, it is unrelated to waste collection. It is part of the exception handling – the try, catch, and finally that you are probably familiar with. This function is used to run the code regardless of whether or not an error occurred.

We studied the distinction between the finalise and finally methods here.

If you have any questions or recommendations, please post them in the comments area below.

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories