Wednesday, March 24, 2010

Declaring an Interface

Declare an interface by using the interface keywords shown in this example:
interface IMyInterface
{
    // interface members
}
The declaration can be modified with a valid combination of access modifiers or the new keyword. It can also be preceded by attributes. The members of an interface can include:
•    Method
•    Properties
•    Indexers
•    Events
The interface cannot, however, contain fields. Interface members are public by default. We cannot use accessibility on them.
The members of an interface are the signatures of methods, properties, indexers, or events. For example:
interface ICounter
{
    void Count(int i);
    int SetCounter();
}
As we can see in this declaration, the interface contains only the names, types, and parameters of methods.
An interface might implement one or more interface, as shown in the following example:
interface IMyInterface: Interface1, Interface2
{
    //interface members
}

No comments:

Post a Comment