C # Interface Basics Tutorial Three

Source: Internet
Author: User
Tags define definition contains interface return string

section III defines interface members

an interface can contain one and more members, which can be methods, properties, index indicators, and events, but not constants, fields, operators, constructors, or destructors, and cannot contain any static members. The interface definition creates a new definition space, and the interface member definition that is directly contained in the interface definition introduces the new member to the definition space.

Description:

1, the member of the interface is a member inherited from the base interface and a member defined by the interface itself.

2. An interface definition can define 0 or more members. The member of the interface must be a method, property, event, or indexer. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types, nor can it contain static members of any kind.

3. Define an interface that contains one: Method, property, event, and indexer for each of the possible kinds of members.

4, the interface member default access mode is public. An interface member definition cannot contain any modifiers, such as a abstract,public,protected,internal,private,virtual,override or static modifier before a member definition.

5. The members of an interface cannot have the same name as each other. The inherited member is not defined, but the interface can define a member with the same name as the inherited member, when we say that the interface member overrides the inherited member, which does not cause an error, but the compiler gives a warning. The way to turn off warning prompts is to add a new keyword before the member definition. However, if you do not overwrite members in the parent interface, the use of the new keyword causes the compiler to issue a warning.

6, the name of the method must be different from the name of all the properties 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 a property or event must differ from the names of all other members defined in the same interface.

8. The signature of an indexer must differ from the signatures of all other indexers defined in the same interface.

9, the attribute (attributes) in the interface method declaration, the return type (Return-type), the identifier (identifier), and the Form argument list (Formal-parameter-lis) have the same meaning as those in a method declaration of a class. An interface method declaration does not allow a method body to be specified, and the declaration usually ends with a semicolon.

10. The accessors of an interface property declaration correspond to the accessors of the Class property declaration, except that the accessor body usually must use a semicolon. Therefore, the accessors are fully determined regardless of whether the property is read-write, read-only, or write-only.

11, the attributes in the interface index declaration (attributes), type (type), and the Form argument list (formal-parameter-list) have the same meaning as those of the class's index declaration.

in the following example, the interface Imytest contains index indicators, event E, method F, and attribute P these members:

Interface imytest{
String This[int index] {get; set;}
Event EventHandler E;
void F (int value);
String P {get; set;}
}
public delegate void EventHandler (object sender, EventArgs e);

in the following example, interface Istringlist contains interfaces for each possible type member: A method, a property, 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;}
}

Total 2 page: previous 1 [2] Next page



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.