Inheritance in C #

Source: Internet
Author: User

First, let's look at a SE engineer class:

//<summary>//     Engineer Class         ///</summary>
Public classSE {/// <summary> ///Work No./// </summary> Public stringID {Get;Set; } /// <summary> ///Age/// </summary> Public intAge {Get;Set; } /// <summary> ///name/// </summary> Public stringName {Get;Set; } /// <summary> ///Sex/// </summary> PublicGender Gender {Get;Set; }}

Look again PM Project Manager class:

//    <summary>
Project Manager class
</summary>
Public classPM {/// <summary> ///Work No./// </summary> Public stringID {Get;Set; } /// <summary> ///Age/// </summary> Public intAge {Get;Set; } /// <summary> ///name/// </summary> Public stringName {Get;Set; } /// <summary> ///Sex/// </summary> PublicGender Gender {Get;Set; }}

Among the two classes, there are many identical fields.

In order to reduce the code, I can put the same code in a public employee class employee

/// <summary>    ///Employee Class/// </summary>     Public classEmployee {/// <summary>        ///Work No./// </summary>         Public stringID {Get;Set; } /// <summary>        ///Age/// </summary>         Public intAge {Get;Set; } /// <summary>        ///name/// </summary>         Public stringName {Get;Set; } /// <summary>        ///Sex/// </summary>         PublicGender Gender {Get;Set; }}

Then we say that the SE class and the PM class are subclasses, and the employee class is our parent class, and the subclass only needs to inherit the parent class, so we don't have to define the parent class properties.

This allows you to reduce the code and clarify the role of the program structure.

For example:

 Public class Se:employee    {}publicclass  pm:employee    {}

: number, which means inheritance.

We can summarize.

Inheritance is an object-oriented feature that can help us remove redundant code from a class.

Inheritance in C #

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.