Information Technology Reference
In-Depth Information
For example, the following code shows the declaration of an interface with two method
members:
Keyword
Interface name
↓
↓
interface IMyInterface1
Semicolon in place of body
{
↓
int DoStuff ( int nVar1, long lVar2 );
double DoOtherStuff( string s, long x );
}
↑
Semicolon in place of body
There is an important difference between the accessibility of an interface and the accessibility
of interface members.
An interface declaration can have any of the access modifiers
public
,
protected
,
internal
, or
private
.
Members
of an interface, however, are implicitly
public
, and
no
access modifiers,
including
public
, are allowed.
Access modifiers are allowed on interfaces.
↓
public interface IMyInterface2
{
private int Method1( int nVar1, long lVar2 ); // Error
}
↑
Access modifiers are NOT allowed on interface members.