Interfaces (Exercise) – Learn C#

7  comments

Interfaces are a very important part of object oriented programming. How can you assure that a class is exposing a certain method? Well, the methods exposed by a class are collectively called an interface. In C# you can use interfaces to literally simplify your life!

This is an exercise for this YouTube video.

Happy learning and good luck!

 

[qsm quiz=10]

Assignment: Create two interfaces and implement them in one class.

 

Click to see the answer
interface IDeleteable
{
    void Delete();
}

interface ICloneable
{
    object Clone();
}

class View : IDeleteable, ICloneable
{
    public void Delete()
    {
        System.Console.WriteLine("Let's pretend that I was deleted.");
    }

    public object Clone()
    {
        System.Console.WriteLine("Let's pretend that I was cloned.");
        return this;
    }
}

 

About the author 

Matt Rešetár

Matt is an app developer with a knack for teaching others. Working as a Flutter Developer at LeanCode and a developer educator, he is set on helping other people succeed in their Flutter app development career.

You may also like

Flutter UI Testing with Patrol

Flutter UI Testing with Patrol
  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
    >