Why to use "finally" block in c#?

0 votes
54 views
Pradeep kumar Patel asked 15 days ago in Programming Language by Pradeep kumar Patel

Why to use "finally" block in c#?

1 Answer

0 votes
Shikhar Arora answered 5 days ago 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
}