-
Is there a reason why internal interfaces can't be implemented by internal methods implicitly? Example: internal interface IFoo
{
void Method();
}
public class Foo : IFoo
{
internal void Method()
{
// CS0737
}
}
internal class Bar : IFoo
{
internal void Method()
{
// CS0737
}
} I know that interface members must be public when implementing them implicitly. But is there a logical reason for that? I mean nothing outside the assembly can use that interface and in my understanding an internal method is just "public inside the same assembly". I also know that I can achieve this via explicit implementation but this is really ugly when it comes to static methods as I can't use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
The escape hatch is that you can always explicitly implement and delegate to an public class Foo : IFoo
{
void IFoo.Method() => this.Method();
internal void Method()
{
// do something
}
} This is a language limitation. The runtime actually is much more flexible about implementations and overrides, name and accessibility may be different as long as the signature is the same. Languages like VB.NET expose this directly: Public Class Foo
Implements IFoo
Friend Sub SomeOtherName() Implements IFoo.Method
' do something here
End Sub
End Class |
Beta Was this translation helpful? Give feedback.
#294