Think of an interface as a promise that a class will implement the methods, properties,
indexers, and events defined in the interface. Interfaces provide definitions of members but do
not provide any implementation. A class that implements an interface is required to provide
an implementation of each of the members of the interface. A class can implement multiple
interfaces, although it can inherit from only one base class. Interfaces can inherit from other
interfaces, just as classes can inherit from base classes.
The C# keywords is and as can be used to work with objects that implement interfaces. The is
keyword is used in a Boolean expression that evaluates to True if an object implements an
interface, and False otherwise. The as keyword converts an object variable to a variable of an
interface type. Expressions that use the as keyword return null if the object does not
implement the named interface.
In this chapter, you examined an example of implementing an interface defined by the .NET
Framework. The .NET Framework implements many interfaces, and you should go through
the documentation and research them all. The interfaces in the .NET Framework begin with
the letter I. Take a look at each one. You can use the .NET Framework interfaces to
implement everything from custom console formatting to serialization to garbage collection
object disposal semantics.