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");
}
}
}