When does a finally block execute in C#?
Correct answer B. After the try block and any catch, whether or not an exception occurred, even after return
Explanation
The finally block runs when control leaves the try statement by any route: normal completion, a return or break, or an exception, caught or propagating. That makes it the place to release resources such as files or locks. It may not run if the process is terminated abruptly, for example through Environment.FailFast or a stack overflow.
Answer checked How we write and check questions
Discussion