Почему разработчик Bloch Pattern не работает в C#

Ваше использование его не является взломом, хотя как много вещей в C++, изменяемом , может быть взломом для ленивого программиста, который не хочет идти полностью назад и отмечать что-то, что не должно быть константой как неконстантой

11
задан Community 23 May 2017 в 12:06
поделиться

4 ответа

In Java private members of inner/nested classes are accessible to the containing class. In C# they aren't.

18
ответ дан 3 December 2019 в 04:53
поделиться

I don't see why that should be allowed to compile. You are trying to access the private fields of a class from outside that class. Java, however, contains a special rule for nested classes that allows access from the outer class.

3
ответ дан 3 December 2019 в 04:53
поделиться

The accessibility levels in C# are as follows:

  • public: Access is not restricted.
  • protected: Access is limited to the containing class or types derived from the containing class.
  • internal: Access is limited to the current assembly.
  • protected internal: Access is limited to the current assembly or types derived from the containing class.
  • private: Access is limited to the containing type.

There is no special case in C# for nested classes, as a result you cannot access a private member from outside that class or any class deriving from that class.

You can find more information in the follow MSDN article: Accessibility Levels (C#)

2
ответ дан 3 December 2019 в 04:53
поделиться

Gilad Bracha argues that allowing outer classes access to the privates of nested classes breaks "the subsumption rule of type systems for OO languages."

0
ответ дан 3 December 2019 в 04:53
поделиться