C # basic interface knowledge Review

Source: Internet
Author: User

First, the interface does not need to use public, because the interface must be public, and the methods in the abstract class can be separated.

Also, the interface cannot contain fields, but can contain attributes.

An error occurred during compilation after changing it to an attribute, because the class that implements the interface must also implement this attribute!

At this time, a small menu will appear when you wait for a moment on the interface name behind the class. After you click the implementation interface, the code will be automatically generated in its inheritance class to reduce the input.

The final test code is as follows:

Class program {static void main (string [] ARGs) {I display player = new screen (); player. in ("video"); player = new digital playback (); player. in (15); console. readline () ;}} interface I show {string STR {Get; set;} Where is the void (object);} Class Screen: I show {public void (where is the object) {console. writeline ("show {0} on the screen", (string) Where);} class digital playback: I show {public void (where the object is) {console. writeline ("{0} in number", (INT) Where);} Public String STR {get {Throw new notimplementedexception ();} set {Throw new notimplementedexception ();}}}

I remember that the abstract class is similar to the interface, and the interface pays more attention to the extraction of the same function. For example, the flight function allows both planes and birds to fly, but it is shown that they do not belong to the same class, there is no inheritance relationship. It is not appropriate to use abstract classes to implement them. Using Interfaces avoids an Inheritance Problem and focuses only on the implementation of functions. In a word, if you have the same functions, you can use the interface (too long ..)

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.