Implementing Interfaces
To implement an interface, you specify the interface name on the class or struct definition after the colon:
When doing so, provide implementations for the interface’s members or mark them as abstract, deferring to a subclass. Two ways to implement interface members are available. The one shown in the preceding snippet is sometimes referred to as implicit interface implementation. When defining the Dispose
method, we didn’t state we’re going to satisfy the contract provided by IDisposable
. As a result, we can call the interface method in a variety of ways:
In the second case, we’re using virtual dispatch mechanisms to ...
Get C# 4.0 Unleashed 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.