. NET Learning notes----2015-07-21 (C # Basics Review 05, Richter conversion)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.