Understanding of Interface (interface) in C #

Source: Internet
Author: User
Tags inheritance

1. All are "imaginary" cannot be instantiated, this is why the interface cannot contain fields--member variables--reason 2. Because the interface is virtual, the index, attributes, time, and so on in the interface can only be declared, but not within the interface, how to implement is derived interface or derived classes.

3. All have the nature of the template, if an interface or class inherits from an interface, it will automatically have the characteristics of the integrator (including indexes, attributes, functions, practices, etc.).

4. Interfaces support multiple inheritance, whereas in C #, classes support a single inheritance, and interfaces actually represent a load capacity,

The following is a simple definition of an interface:

interface
SampInterface1
{
  string
  this[ int index]
  {
    get;
    set
  }
  ;
  event EventHandler Event;
  void Find( int value );
  //注意此处没有
  {
  }
  
  string Po
  int
  {
    get;
    set
  }
  ;
}

The above interface defines an index

This, a practice event, a method find and a property point.

public interface SampIneterface:SampIneterface1{
pravite int a=1;
void find (int value)
{
a+=value;
}
event EventHandler Event;
protected void onEvent()
{
if(Event=null)
{return Event(this.System.EventAgrs.Empty;)}
}

}

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.