While there are many tutorials out there on OOP(Object Oriented Programming), we are taking a different approaching in how we help you learn by giving out easy to understand self-explanatory examples.

For example in this article we will be covering Interface examples. Learn Interfaces, how to define and implement them using the examples covered in this tutorial.

Example – Simple C# Interface Example

Learn how to create an interface then implement them.

Step 1: Create Interface

Here is how you create an interface:

interface Baby
{
    void cry();
}

Step 2: Implement interface

Then you need to create a class to implement the interface functionalities/methods.

    class Kyle:Baby
    {

        public void cry()
        {
            Console.WriteLine("Nge nge nge nge");
        }

//....

Step 3: Invoke the functionality

Finally to invoke the method:

        static void Main(string[] args)
        {
            Baby baby = new Kyle();
            baby.cry();
        }

Full Code

Here is the full code:

using System;

interface Baby
{
    void cry();
}
namespace InterfaceDemo
{

    class Kyle:Baby
    {

        public void cry()
        {
            Console.WriteLine("Nge nge nge nge");
        }

        static void Main(string[] args)
        {
            Baby baby = new Kyle();
            baby.cry();
        }

    }

}

Run

If you run the code you will get the following:

Nge nge nge nge