What version of C# stopped requiring protected interface members to be implemented explicitly?

  Kiến thức lập trình

In C# 8, interfaces were upgraded to allow protected members, among other access modifiers. At the time, implementing classes were required to explicitly implement such protected interface members.

So, under C# 8 this code:

public interface IFoo
{
    protected void Method();
}

public class Foo : IFoo
{
    public void Method()
    {
    }
}

produces this compilation error:
CS8704 'Foo' does not implement interface member 'IFoo.Method()'. 'Foo.Method()' cannot implicitly implement a non-public member.

I hadn’t written any code that took advantage of this “feature” (force the hiding of implementer specific helper methods from normal public access) lately, but recently I noticed that the explicit implementation is no longer required. The code snippet above now compiles without issue (as of C# 11 at least). Why/when did this change? I couldn’t find any documentation or discussion of the change, did it happen incidentally due to other language changes?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT