O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining Interfaces

To declare an interface, you use the interface keyword rather than class or struct. In the interface body, zero or more members can be specified, without any implementation provided. For example:

public interface IDisposable{    void Dispose();}

All this says is that a type implementing this interface promises to support the disposal operation by providing an implementation for the Dispose method.

Note: Contracts or Not?

Where some people disagree with the idea of interfaces as contracts is that they do not really specify a “complete contract” beyond a series of signatures that are merely a syntactic concern. For example, what’s a type supporting IDisposable supposed to do if Dispose is called multiple times? Or what does ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required