Implementing Interfaces in microsoft dotnet

The syntax for defining an interface is very similar to the syntax for defining a class or a struct:

[attributes ] [access-modifier ]
interface interface-name [: base-list ] {interface-body }

Access modifiers (public, private, etc.) work just as they do with classes. It is common (but not required) to begin the name of your interface with a capital I

The body of the interface is defined within braces, just as the body of a class would be.

Suppose you want to create an interface to define the contract for data being stored to a database or file. Your interface will define the methods and properties a class will need to implement in order to be stored to a database or file. You decide to call this interface IStorable.

In this interface, you might specify two methods, Read() and Write(),

which appear in the interface body:

No comments:

Post a Comment