Public and Internal members in an Internal class?

后端 未结 5 814
暗喜
暗喜 2020-12-25 11:00

Ok, so this may be a bit of a silly question, and there\'s certainly the obvious answer, but I was curious if I\'ve missed any subtleties here.

Is there any differen

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 11:18

    Consider this case:

    public interface IBar { void Bar(); }
    internal class C : IBar
    {
        public void Bar() { }
    }
    

    Here C.Bar cannot be marked as internal; doing so is an error because C.Bar can be accessed by a caller of D.GetBar():

    public class D
    {
        public static IBar GetBar() { return new C(); } 
    }
    

提交回复
热议问题