interface Part2 (defined interfaces)

 

A. In the  C #  language, the inheritance relationship between class supports only single inheritance, but the interface to achieve multiple inheritance design.

II. A class can implement multiple interfaces simultaneously, and then also in the realization of other classes inherit interface between the interface and may also inherit.

Third, whether it is inherited between represent classes or class inheritance between the interface, the interface with the interface, use the ":" to represent. ',' Separated by commas between the plurality.

 

definition:

  interface name
  {
      interface member;
  }

  1. Interface Name

  I usually begin with, plus other words constituted. Such as creating a computing interface, it can be named ICompute. 

  2. Interface members

  Similarly members of the members of the class defined in the interface defined. Must meet the following conditions:

  Members of the defined interface must meet the following requirements.

    1). The interface member is not allowed to use public, private, protected, internal access modifier. The default is public, you do not need modification.

    2). Interface members are not allowed modifier static, virtual, abstract, sealed and so on.

    3) Among the interfaces can not be defined fields.

    4). The method defined in the interface does not have a body .

 

[Example] create an interface Interface ICompute calculate student achievement, and are defined in the interface to calculate the total score, the average score of the method.

public interface ICalculateScore
{
  int Id { get; set; }
  string Name { get; set; }
  void Total();
  void Avg();
}

Provision can not create an instance of the interface directly, only through the class interface methods implemented in C # language.

Guess you like

Origin www.cnblogs.com/lu-yuan/p/11345817.html