Richter conversion:
1, subclasses can be assigned to the parent class
2. If a child class object is loaded in the parent class, you can convert the parent class to a subclass object.
3, as
4, is
If a subclass inherits a parent class, the subclass can use the members inherited from the parent class in addition to its own members.
However, the parent class can always use only its own members, not the members of the child classes
Sub-classes cannot use each other's members
classProgram {Static voidMain (string[] args) { person person=NewStudent (); Teacher T= Person asTeacher;//The as conversion succeeds to the corresponding object, and the conversion fails to return null//Student s = (Student) person;//The conversion succeeds, because the person is loaded with student objects.//Teacher s = (Teacher) person;//The conversion failed because the person with the student object if(Person isStudent) {Console.WriteLine ("OK, you can convert"); } Else{Console.WriteLine ("No , can not be converted"); } //Console.WriteLine (s.id);Console.readkey (); //Student Student = new Student (); //Teacher Teacher = new Teacher (); } } Public classPerson { Public stringName {Get;Set; } } Public classStudent:person { Public intID {Get;Set; } } Public classTeacher:person { Public DoubleSalary {Get;Set; } }
. NET Learning notes----2015-07-21 (C # Basics Review 05, Richter conversion)