Using Interfaces

In C#, you can't inherit from multiple base classes at the same time. For example, if Window and Graphics are classes, deriving a class named Menu from them like this is illegal:

public class Menu : Window, Graphics   // Illegal

However, like Java, C# supports Java-style interfaces, which C# treats as a contract, indicating that a class will implement a certain set of properties, methods, events, and/or indexers. Unlike base classes, interfaces don't implement any of their members by providing the actual code for properties, methods, and so on. Interfaces are just specifications for those members, and if your class implements an interface, it must provide code for all the members of that interface. A single class can implement ...

Get Microsoft® Visual C#® .NET 2003 Kick Start 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.