1. Richter transformational grammar:
1) subclass can be assigned to the parent class: If there is a need to place a parent class as an argument, we can give instead of a subclass
Person p = new Student();
2). If the parent class is loaded with subclass object, then this can be converted to the parent subclass object
Student stu = (Student)p
And as 2.is
1) is: indicates the type of conversion, if the conversion can be successful, returns true, otherwise returns false;
Person p = new Student();
if (p is Teacher)
{
Student stu = (Student)p;
stu.StudentPrint();
}
else
{
Console.WriteLine("转换失败");
}
2) as: indicates the type of conversion, if the object can be converted to the corresponding return, otherwise it returns a null;
Teacher tea = p as Teacher;
if (tea == null)
{
Console.WriteLine("转换失败");
}
else
{
tea.TeacherPrint();
}
Reproduced in: https: //www.cnblogs.com/zwj-199306231519/p/11027038.html