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.
LVL 8
CamilliaAsked:
Who is Participating?
 
wht1986Commented:
oops sorry cut and paste just use the virtual on Class1 not the interface

    public interface ISecurable
    {
        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; }
        }      
    }
0
 
wht1986Commented:
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; }
        }      
    }
0
 
CamilliaAuthor Commented:
let me try
0
 
wht1986Commented:
any luck?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.