?
Solved

Simple interface implementation error

Posted on 2009-04-15
4
Medium Priority
?
209 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:Camillia
  • 3
4 Comments
 
LVL 12

Expert Comment

by:wht1986
ID: 24154177
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
 
LVL 12

Accepted Solution

by:
wht1986 earned 2000 total points
ID: 24154181
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
 
LVL 7

Author Comment

by:Camillia
ID: 24156478
let me try
0
 
LVL 12

Expert Comment

by:wht1986
ID: 24159710
any luck?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question