Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Simple interface implementation error

I have an interface like this:
 public interface ISecurable
    {
        bool CanCreate
        {
            get;
        }
}

--***** I create a class and implement this interface.I click on the interface name and it creates this:

     bool ISecurable.
        {
            get { throw new NotImplementedException(); }
        }

*** Then i want to override that interface's CanCreate, I do this but get an error that overridable method doesnt exist:

  public override bool CanCreate //***error here
       { get { return true; } }

            bool ISecurable.CanCreate
       {
           get { return CanCreate; }
       }


*** when I type public override (at this point, intellisense doesnt give me "bool") I manually type it.
Avatar of wht1986
wht1986
Flag of United States of America image

the implementation like the below is correct:

    public interface ISecurable
    {
        bool CanCreate { get; }
    }

    public class Class1: ISecurable
    {
        public bool CanCreate
        {
            get { return true; }
        }
    }


Are you trying to make another class then that inherits from the derived class (Class1 in my instance) and then override it?  If thatst he case u need to make the property as virtual

    public interface ISecurable
    {
        virtual bool CanCreate { get; }
    }

    public class Class1 : ISecurable
    {
        public virtual bool CanCreate
        {
            get { return true; }
        }
    }

    public class Class2 : Class1
    {
        public override bool CanCreate
        {
            get { return false; }
        }      
    }
ASKER CERTIFIED SOLUTION
Avatar of wht1986
wht1986
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

let me try
any luck?