C # differences between interfaces and Classes)

Source: Internet
Author: User
Differences between interfaces and classes in C #
1. interfaces are similar to classes, but they do not have execution methods. They are only a combination of methods, attributes, events, and index characters. They can only contain these four types of members; in addition to the four types of members, the class can also have other members (such as fields ).
2. An interface cannot be instantiated. An interface only includes the signature of a member, and a class can be instantiated (except abstract class ).
3. The interface has no constructor and the class has constructor.
4. The interface cannot be overloaded with operators, and the class can be overloaded with operators.
5. Interface Members do not have any modifiers, and their members are always public, while Class Members can have modifiers (such as virtual or static ).
6. The class derived from the interface must implement the execution method of all the members of the interface, but the class is not derived from the interface.
Why is there an interface? The main reason is that it is a valid contract. The class has some members, and they are not considered to be combined. The class is just a list with various methods, fields, and attributes, but in order to use the class in some way, you must know the functions that the class can execute. The specific operation is to declare the class that executes one or more interfaces. The class execution interface is derived from the interface, then, the execution method of all Members defined in this interface is provided.
Related Article

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.