Shousha
Shousha

Reputation: 53

No suitable method found to override but there is an method to be overridden

I have created a simple interface with the below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPattern_FactoryPattern
{
   interface Shape
    {
       void drawshape();
    }
}

Then, I have created another class with the below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPattern_FactoryPattern
{
    class Square : Shape
    {
        public override void drawshape() 
        {
            Console.WriteLine("Shape is Square");
        }
    }
}

I got the following error:

No suitable method found to be override.

Could you please help me?

Upvotes: 1

Views: 4441

Answers (1)

Olivier De Meulder
Olivier De Meulder

Reputation: 2501

So you have:

  • an interface named Shape
  • a class named Square that implements the Shape interface

In that case, you need to drop the word override. The drawShape method in your Square class is the implementation of the method defined in the interface.

Let's say you had a base class named Shape and you had the Square class inherits from Shape. That is a case where the drawShape method would override the method of the same name in the base class.

Upvotes: 4

Related Questions