-2

I am receiving this error:

CalculatorCalories does not implement interface member ICalculatorCalories.GetIndex

But I implemented the interface's method:

namespace WindowsFormsApp1
{
    public interface ICalculatorCalories
    {
        int GetIndex { get; }
    }

    public partial class CalculatorCalories : Form, ICalculatorCalories
    {
        public CalculatorCalories()
        {
            InitializeComponent();
        }

        public int GetIndex(int growthC, int sex)
        {
            int index = growthC - 100 - ((growthC - 150) / sex);
            return index;
        }
    }
}
1
  • GetIndex is a property! Not a method Commented Dec 21, 2020 at 10:39

2 Answers 2

4

The problem is because the interface defines a readonly property, where the implementation's GetIndex is a method. You need to change one or the other.

Presumably, edit your interface to:

public interface ICalculatorCalories
{
    int GetIndex(int growthC, int sex);
}
Sign up to request clarification or add additional context in comments.

Comments

3

In ICalculatorCalories you've defined GetIndex as a getter property instead of the function that you've implemented. In order for the class to implement the interface, the signature of the methods/properties must match.

Suggest fixing the interface:

public interface ICalculatorCalories
{
    int GetIndex(int growthC, int sex);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.