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语句.

posted @ 2010-12-04 00:29  庚武  Views(230)  Comments(0Edit  收藏  举报