class Program
{
static void Main(string[] args)
{
//里式转换
//1.子类可以赋值给父亲,如果一个地方需要父类,可以给一个子类替代
//2.如果父类装的是子类对象,那么这个对象将强制转化为子类
//如果子类方法与父类方法重名,那么将隐藏父类成员
//is 多用于判断,如果成功返回true,失败返回false
//as 成功返回相应类型,失败则返回null
Person p = new Person();
Student s = new Student();
p = s;
p.SayHi();
Student s1=(Student)p;
s1.SayHi();
if(p is Student)
{
Console.WriteLine("转换成功");
}
else
{
Console.WriteLine("转换失败");
}
Console.ReadKey();
}
}
class Person
{
public void SayHi()
{
Console.WriteLine("我是人类");
}
}
class Student:Person
{
public new void SayHi()
{
Console.WriteLine("我是学生");
}
}