4.3. Defining an Interface

In Section 4.1 we implemented a new instance of an existing interface. In Section 4.2 we simply discovered and used the interface associated with a given type. In this section we introduce an interface definition. This interface supports the generation and display of sequences of numbers based on a unique algorithm. Here is the general set of operations we wish to support (two methods, a property, and an indexer):

  • GenerateSequence(), which generates the unique sequence of elements

  • Display(), which outputs the elements

  • Length, which returns a count of the number of elements

  • Indexer, which allows the user to access a specific element

An interface definition begins with the keyword interface followed by a name. Recall that ...

Get C# Primer: A Practical Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.