Camillia
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
let me try
any luck?
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; }
}
}