0

If I have an interface

interface ISite {
    int g { get; set; }
}

and a base class

class Site {
    public int g = 1;
}

and a derived class that implements the interface and extends the class

class DSite : Site, ISite {
    // comaplains g is not defined
}

It complains that I did not implement the g property, but how do I make it take it from the parent class Site?

1 Answer 1

1

Either make g in Site a property:

class Site
{
    public int g {get;set;} = 1;
} 

or explicitly implement the interface in DSite:

class DSite : Site, ISite
{
    int ISite.g
    {
        get { return g; }
        set { g = value; }
    }
}
Sign up to request clarification or add additional context in comments.

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.