C# Interfaces
In this chapter you will learn:
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 {// ww w . ja v a2s . c om
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.
Next chapter...
What you will learn in the next chapter:
- How to implement an interface
- Code to show how to create and implement interface
- Multiple Implementation: implement two interfaces
- extend class and implement interface at the same time