Use of the C # interface

Source: Internet
Author: User

In the previous article on the abstract class, the actual interface and the use of abstract classes there is no big difference they can only be inherited. But the use of the environment is not the same. Abstract classes use functions that compare a set of things. But the interface is biased toward something that does not understand the intersection of functions. Let's take a look at how it's used, and the code looks like this:

Define a USB interface Interface iusb    {        void  usb ();     }    //define a NIC interface     interface  Networkcard    {        void networkcard ();     }    //defines a computer that has these interface features     public class  computer1 : IUSB, Networkcard    {         public void usb ()  {             messagebox.show ("This is a usb1.0 interface");           }        public void networkcard ()          {             MessageBox.Show ("This is a NIC interface");         }    }    public class  computer2 : iusb, networkcard    {         public void usb ()  {             messagebox.show ("This is a USB2.0 interface");           }         public void networkcard ()          {             MessageBox.Show ("This is a NIC interface");        }    }     private void button1_click (object sender, eventargs e)          {             Computer1 cmp = new compUter ();             cmp.usb ();             cmp.networkcard ();             //can do the same            / / iusb iusb = cmp;             Iusb.usb ();                     }

I believe that people from the code, more than the text narrative easier to understand it. This is the function of the interface.

Use of the C # interface

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.