Why can't I have protected interface members?

后端 未结 13 1910
走了就别回头了
走了就别回头了 2020-11-29 19:58

What is the argument against declaring protected-access members on interfaces? This, for example, is invalid:

public interface IOrange
{
    public OrangePee         


        
13条回答
  •  悲哀的现实
    2020-11-29 20:15

    Interface members are a public API; things like protected etc are implementation details - and interfaces don't have any implementation. I suspect what you are looking for is explicit interface implementation:

    public class NavelOrange : IOrange
    {
        public OrangePeel Peel { get { return new OrangePeel(); } }
        OrangePips IOrange.Seeds { get { return null; } }
    }
    

提交回复
热议问题