An overview of the implementation of CSharp polymorphism

Source: Internet
Author: User

(1) What is polymorphic, polymorphic is a class that shows a variety of different forms, and his core is that the subclass object is used as the parent object

(2) How to achieve polymorphism, in the CSharp, you can use the interface, virtual method, abstract class to achieve polymorphism, of course, regardless of the three kinds of the one to achieve polymorphism, need to rely on inheritance to achieve

(3) First look at what is an interface, interface can be regarded as a standard, all inherited subclasses need to follow the method declared in the interface to implement

(4) Then look at what is a virtual method, the virtual method is modified with virtual, overridden in the subclass with override, it is a method placed in the class, you can choose to rewrite in the subclass, or do not rewrite

(5) Finally look at what is abstract class, abstract class is a virtual class, can not create objects, with the abstract decoration, if the subclass is also an abstraction class, then all the abstract methods in the parent class, the property does not have to implement all; If the subclass is not an abstract class, all the abstract methods in the parent class must be fully implemented

Implementation of CSharp Polymorphism (virtual method)

Implementation of CSharp polymorphism (abstract class)

Implementation of CSharp polymorphism (interface)

An overview of the implementation of CSharp polymorphism

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.