C# Interfaces

Description

An interface provides a specification rather than an implementation for its members.

A class can implement multiple interfaces. In contrast, a class can inherit from only a single class.

Interface members are all implicitly abstract.

Structs can implement interfaces.

Syntax

Interfaces are declared by using the interface keyword. Here is a simplified form of an interface declaration:


interface name {//from   w  w w . j  a va2 s.  c o m
   ret-type method-name1(param-list);
   ret-type method-name2(param-list);
   // ...
   ret-type method-nameN(param-list);
}

Note

Interface members are always implicitly public and cannot declare an access modifier.

Implementing an interface means providing a public implementation for all its members.

You can implicitly cast an object to any interface that it implements.





















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor