Reputation: 33
Actually the code below is Simple example of interface.But it showing an error 'PublicDemo.DemoPublic' does not implement interface member 'PublicDemo.demo1.two()'. 'PublicDemo.DemoPublic.two()' cannot implement an interface member because it is not public.
namespace PublicDemo
{
public interface demo
{
void Demo();
}
public interface demo1:demo
{
void one();
void two();
}
class DemoPublic :demo1
{
protected internal string variable;
public void Demo()
{
Console.WriteLine("{0}", variable);
}
public void one()
{
Console.WriteLine("this is one method");
}
protected void two()
{
Console.WriteLine("this is two method");
}
}
class Excute : DemoPublic
{
static void Main(string[] args)
{
Excute Dp = new Excute();
Dp.variable = Console.ReadLine();
Dp.Demo();
Dp.one();
Dp.two();
Console.ReadKey();
}
}
}
i need why it is not working
Upvotes: 0
Views: 64
Reputation: 73462
You yourself answered the question:
'PublicDemo.DemoPublic.two()' cannot implement an interface member because it is not public.
Answer is Interface members have to be public.
Upvotes: 1
Reputation: 2370
It means what is says. Your two method is protected. It needs to be public if implemented from an interface.
protected void two(){
Console.WriteLine("this is two method"); }
change it to public
Upvotes: 0
Reputation: 728
Change Protected to Public.You have defined an public Interface.Once you define Public Interface,the Contracts in the Interface also will be public by Default.
public void two()
{
Console.WriteLine("this is two method");
}
Upvotes: 0
Reputation: 14640
Change
protected void two()
{
Console.WriteLine("this is two method");
}
into
public void two()
{
Console.WriteLine("this is two method");
}
Upvotes: 1