Why to use "finally" block in c#?

0 votes
173 views
Pradeep kumar Patel asked 01-Nov-2019 in Programming Language by Pradeep kumar Patel

Why to use "finally" block in c#?

1 Answer

0 votes
Shikhar Arora answered 12-Nov-2019 by Shikhar Arora
Finally keyword is a reserved keyword in C#.Finally block executes when the try/catch block leaves the execution, no matter what condition caused it. It always executes whether the try block executes normally or without any exception.The main purpose of finally block is to release the system resources.
try

{
 //code
}
catch
{
 //code
}
finally
{
 //code
}