I have code
internal interface IFoo
{
void foo();
}
public class A : IFoo
{
// error CS0737: 'A' does not implement interface member 'IFoo.foo()'.
//'A.foo()' cannot implement an interface member because it is not public.
internal void foo()
{
Console.WriteLine("A");
}
}
Why such strange limitation? I have internal interface and why I can’t create internal method in interface realization?
This is because interfaces can’t specify anything about the visibility of members, only the members themselves. All members that implement an interface must be
public. The same happens when you implement aprivateinterface.One solution might be explicitly implementing the interface:
In the above code, you must have an instance of
Acast toIFooto be able to callfoo(), but you can only do such a cast if you areinternalcompared to the class and hence have access toIFoo.