The return statement is used to exit a method of a class, returning control to the caller of the method.
If the return statement is inside a try block, the finally block(if one exists) will be executed before control returns to the calling method.
using System; Console.WriteLine($"Get value: {Test()}"); int Test() { try { return 2 * 5; } catch (System.Exception) { throw; } finally { Console.WriteLine("This is from finally."); } }
Output:
This is from finally.
Get value: 10