Chapter 17. Interfaces
What Is an Interface?
An interface is a reference type that represents a set of function members, but does not implement them. Other types—classes or structs—can implement interfaces.
To get a feeling for interfaces, I'll start by showing one that is already defined. The BCL declares an interface called IComparable
, the declaration of which is shown in the following code. Notice that the interface body contains the declaration of a single method, CompareTo
, which takes a single parameter of type object
. Although the method has a name, parameters, and a return type, there is no implementation. Instead, the implementation is replaced by a semicolon.
Figure 17-1 illustrates interface IComparable
. The CompareTo
method is shown ...
Get Illustrated C# 2008 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.