using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 子類與父類的相互轉換 { class Program { static void Main(string[] args) { //try catch finally 與 continue //若是在try中遇到continue,則忽略try中continue以後的語句 //可是依然執行finally中語句 //finally以外的語句也不執行 bool _flag = true; while(true) { try { if(_flag) continue; //若是_falg爲true,這下面的兩句不執行 Person per = new Student(); per.Say();//此時輸出father } catch (Exception ex) { throw ex; } finally { //若是try中執行了continue,則這兩句依然要執行 Console.WriteLine("finally"); Console.ReadKey(); } //若是在try中執行continue,則下面的兩條語句並不執行 Console.WriteLine(); Console.ReadKey(); } } } class Person { public void Say() { Console.WriteLine("father"); } } class Teacher:Person { public void Say() { Console.WriteLine("Teacher"); } } class Student:Person { public void Say() { Console.WriteLine("Student"); } } }