kinsell
kinsell

Reputation: 358

Error: Does not implement interface member

I'm new to c#, and I'm kinda struggling with implementing interfaces, gonna be very grateful if someone helps me with this, with an explanation. Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace interfejsi
 interface Figura
{
  String Plostina ();
  String Perimeter ();
}
}
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 namespace interfejsi
{
 class Kvadar : Figura
{
    int a,b,c;
    public  String Perimetar(int a, int b, int c)
    {
        return (a + b + c).ToString();
    }
    public String Plostina(int a, int b, int c)
    {
        return (a * b * c).ToString();
    }
}

}

Upvotes: 6

Views: 47287

Answers (2)

SynerCoder
SynerCoder

Reputation: 12766

The Method definitions do not match. In the interface the Method String Plostina () is defined, but the class does not have that method. The method in the class has a different signature, in the class it looks like String Plostina(int a, int b, int c).

To implement an interface, the Name, return type and parameters (amount, order and type) must match.

Upvotes: 1

Amir Popovich
Amir Popovich

Reputation: 29836

You need to implement the exact functions that sit in the interface(with the same number of input params)..

So in you case change your interface to:

interface Figura
{
   String Perimetar(int a, int b, int c)
   String Plostina(int a, int b, int c)
}

Or change you implementation to functions with no params.

Upvotes: 7

Related Questions