Define interface member

xiaoxiao2021-03-06  53

Third quarter

Define interface member

The interface can contain one and multiple members, which can be methods, attributes, index indicators, and events, but cannot be constant, domain, operator, constructor or destructuring function, and cannot contain any static members. Interface Defines Creating a new definition space and interface definitions directly included interface member definitions introduce new members into the definition space.

Description:

1. Members of the interface are members from the base interface and the members defined by the interface itself.

2. Interface definitions can define zero or more members. The member of the interface must be a method, attribute, event, or an indexer. The interface cannot contain constants, fields, operators, instance constructor, destructuring functions, or types, nor can no static members of any kind.

3. Define an interface that contains one: method, attribute, event, and indexer for each possible group.

4. Interface members' default access method is public. Interface member definitions cannot contain any modifiers, such as the member definitions that cannot be added to Abstract, Public, Protected, Internal, Private, Virtual, Override, or Static modifiers.

5. The members of the interface cannot be mutually known. The successful member does not need to be defined, but the interface can define members of the same name as inherited, then we say that the interface member covers the inherited member, but the compiler will give one caveat. Closing a warning prompt is to add a new key before the member definition. However, if there is no member in the parent interface, use the new keyword to cause the compiler to warn.

6. The name of the method must be different from all attributes and events defined in the same interface. In addition, the signature of the method must be different from the signature of all other methods defined in the same interface.

7, the name of the property or event must be different from the names of all other members defined in the same interface.

8, a signature of an indexer must be different from the signature of all other indexes defined in the same interface.

9. Attributes in the interface method declaration, the return type, the Identifier, and the form of formal-parameter-lis and the same meaning in the method declaration of a class. . An interface method declaration does not allow designation of a method main body, and the declaration usually ends with a semicolon.

10. The visitor of the interface attribute declaration corresponds to the visitor of the class attribute declared, in addition to the visitor, usually must use a semicolon. Therefore, regardless of the attribute is read or written, only written or only written, the visitor is fully determined.

11. Attributes, Types, and Form-Parameter-Lists in the interface index declaration have the same meaning as those index declarations of the class.

The interface ImyTest contains an index indicator, event E, method F, attribute P:

Interface IMYTEST {String this [int index] {get; set;} event even; void f (int value); string p {get; set;}} public delegate Void EventHandler (Object Sender, Eventargs E);

The interface istringlist in the following example contains interfaces for each possible type of member: a method, an attribute, an event, and an index.

public delegate void StringListEvent (IStringList sender); public interface IStringList {void Add (string s); int Count {get;} event StringListEvent Changed; string this [int index] {get; set;}} full name of the interface members

Full Qualified Name can also be used using interface members. The full name of the interface is constituted. The interface name plus small dots "." Retraway, such as the following two interfaces:

Interface icontrol {void Paint ();} interface itextbox: icontrol {void gettext (string text);}

Where Paint's full name is iControl.Paint, the full name of GetText is ITextBox. GetText. Of course, the name of the member in the full name must be defined in the interface, such as use iTextBox.paint. Is unreasonable.

If the interface is a member of the namespace, the full name must also contain the name of the namespace.

Namespace system {public interface iDataTable {Object Clone ();}}

Then the full name of the Clone method is system. IDATATABLE.CLONE.

Define the interface, how to access the interface, please see the next section - Access interface

转载请注明原文地址:https://www.9cbs.com/read-83895.html

New Post(0)