“Inconsistent accessibility” on class definition

后端 未结 3 1845
一向
一向 2020-12-19 17:46

I\'m adding some bindable CLR properties to my ongoing WPF application in my App class and I can\'t compile because of this inconsistent accessibility error.

相关标签:
3条回答
  • 2020-12-19 18:03

    Don't know about vb, but in c# classes defaultly have as restrictive modifiers as possible, which means - they are internal, unless they are nested within another class - in that case they are private.

    Here's a complete guide (-:

    0 讨论(0)
  • 2020-12-19 18:10

    While it's generally considered good practice to be explicit in all access modifiers, it's not unreasonable to allow them to be omitted with some sort of default.

    Of course that default has to be sensible. If the default was public and it was used inappropriately then there would be no way to statically determine it was a mistake (unless it exposed a type that is elsewhere defined with less access), code could go for months or years before someone noticed the flaw, and then fixing it would be a breaking change to the assembly.

    Because the default is private where applicable and internal in all other cases, then if this is a mistake it'll result in a compiler error (as something needs it to have greater access) which is caught easily, or in a class simply not being visible to other assemblies (easily caught, especially with most IDEs).

    Restrictive defaults are therefore the obvious way to go.

    0 讨论(0)
  • 2020-12-19 18:18

    Things declared outside of a class or struct will default to internal. Things declared inside of a class or struct will default to private. refer http://msdn.microsoft.com/en-us/library/ba0a1yw2(VS.80).aspx

    0 讨论(0)
提交回复
热议问题