Public and Internal members in an Internal class?

后端 未结 5 796
暗喜
暗喜 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:03

    Just faced with another example where there is difference between those two, when used from XAML in WPF.

    XAML:

    Code with internal enum compiles successfully:

    internal class Foo
    {
        internal enum Bar
        {
            e1,
            e2,
        }
    }
    

    But surprisingly changing it to public results in error:

    internal class Foo
    {
        public enum Bar
        {
            e1,
            e2,
        }
    }
    

    The last example produces compilation error:

    error MC3064: Only public or internal classes can be used within markup. 'Bar' type is not public or internal.

    Unfortunately, I can't explain what's wrong with public in this case. My guess is "just because WPF works that way". Just change modifier of the nested class to internal to get rid of error.

提交回复
热议问题