1

I am getting this error while compiling the code and not able to figure out the exact reason:

Class does not implement interface member

This is my code:

interface IReview<T> where T : Review
{
    IEnumerable<T> Reviews { get; set; }

    void AddReview<T>(T item);  
}

class ReviewCollection : IReview<Review>
{
    IEnumerable<Review> _reviews;

    public IEnumerable<Review> Reviews
    {
        get { return _reviews; }
        set { _reviews = value; }
    }

    public void AddReview(Review item)
    {

    }
}

What is the issue with it?

3 Answers 3

3

Your definition of AddReview in the interface is wrong. It should read:

void AddReview(T item);  

The generic type argument T is already provided by the class, and you don't want to deviate in your method (in this case). You now changed the meaning of T to be a local type parameter, not to use the one available on the class level.

Sign up to request clarification or add additional context in comments.

Comments

0

You didn't implement the generic method:

public void AddReview<Review>(Review item)
{    
}

Or you should change the signature of the method in your interface:

void AddReview(T item);

Comments

0

You might have to change this method:

public void AddReview(Review item)

To this:

public void AddReview<Review>(Review item)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.