Creating the interface
Let's take a look at switch
blocks in action. Create a new C# console app, clear out the existing code, and start typing this:
using static System.Console;
We need this line, of course, so that we can use WriteLine
. Next, we're going to make an interface that we'll call Movable
:
interface Movable { void Move(); }
This interface only has one method, called Move
. Remember, the purpose of an interface is to bind a variety of different, essentially unrelated, class types together. What does this mean? It's basically a contract on the functionality, not data essentially. Let's take a look at this in action by implementing the interface.