Try Catch Finally Retrun demo
class Program { static void Main(string[] args) { int res = ReturnTest(1); Console.WriteLine(res); Console.ReadKey(); } static int ReturnTest(int i) { try { i++; return i; } catch (Exception ex) { return -1; } finally { i++; } } }
finally语句块中,i将变成3,但res=2.
结论:在return之后,再执行finally语句.