C#: Inconsistent accessibility: property type

前端 未结 4 1712
南笙
南笙 2020-12-06 04:00

What\'s wrong with

public partial class MainWindow : Window
{
    public ObservableCollection Tabs { get; set; }
    public ICollectionV         


        
4条回答
  •  一生所求
    2020-12-06 04:57

    MakeTabViewModela public type too.

    Obviously, it doesn't make sense for a public property on a public containing-type to be of a type that is not public. How could the property present itself to external assemblies?

    Your second sample works because, as a general rule, providing no accessibility modifiers means that the least applicable modifier is chosen as the default - in this case: private. Clearly, there are no consistency issues with declaring a private property of an internal (?) type.

提交回复
热议问题