C # Interface

Source: Internet
Author: User

About Interfaces
<1> interface content: method, attribute, indexer, and event.
<2> the interface members are public and abstract automatically. No modifiers can be added.
<3> interfaces are inherited in essence. When the interface methods are implemented implicitly, they cannot be overwritten.
<4> explicit interfaces cannot be modified using public or abstract statements. Explicit interfaces cannot be overwritten.
<5> when an explicit interface is called, it can only be called by itself. Example:

namespace ConsoleApplication10Inter{    interface Interd1    {        void draw();    }    interface Interd2    {        void draw();    }    class Class2 : Interd1,Interd2    {        void Interd1.draw()        {            Console.WriteLine("draw in interface1");        }        void Interd2.draw()        {            Console.WriteLine("draw in interface2");        }    }    class Program    {        static void Main(string[] args)        {            Class2 T = new Class2();            Interd1 d1 = (Interd1)T;            d1.draw();            Interd2 d2 = (Interd2)T;            d2.draw();        }    }}


<6>

An interface is similar to an abstract base class: any non-Abstract type that implements an interface must implement all the members of the interface.
The interface cannot be instantiated directly.
Interfaces can contain events, indexers, methods, and attributes.
The interface does not contain the implementation of methods.
Classes and structures can inherit multiple interfaces.
The interface itself can be inherited from multiple interfaces.


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.