C#中的try catch finally用法分析

2019-12-26 11:20:02王冬梅

{
    public class Complex
    {
        static void Main(string[] args)
        {
            int i = 2008;
            int j = 2;
            try
            {
                int result = i / j;
            }
            catch
            {
                Console.WriteLine("J变量的值为0");
            }
            finally
            {
                Console.WriteLine(j.ToString());
            }
            Console.Read();
        }
    };
}

 

程序输出为:

0

希望本文所述对大家的C#程序设计有所帮助。