题目描述
数组越界,捕获、清除处理异常。(控制台应用程序)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 清除处理所有异常 { class Program { static void Main(string[] args) { int[] myint = { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }; try { for (int i = 0; i < myint.Length; i++) { int temp = 720 / myint[i]; Console.WriteLine("720÷{0}={1}", myint[i], temp); } } catch (Exception myexc) { Console.WriteLine(myexc.Message.ToString()); } finally//用于消除try块中分配的任何资源以及运行任何即使在发生异常时也必须执行的代码 { Console.WriteLine("什么时候都会执行,无论发生异常与否"); } } } }