Tuesday, 15 November 2011

Access Modifiers

1. So these are - Private, Protected, Internal, ProtectedInternal and Public.
2. Class/Struct can have Internal(default)/Public.
3. Struct members (nested class & structs etc) can have - Private(default), Internal and Public.
4. Class members (nested class & structs etc) can have - Private(default), Protected, Internal, ProtectedInternal and Public.
5. Default Access modifier for class constructor is - protected.
6. Friend assemblies - InternalsVisibleToAttribute.
7. Derived classes cannot have greater accessibility than their base types. In other words, you cannot have a public class B that derives from an internal class A. If this were allowed, it would have the effect of making A public, because all protected or internal members of A are accessible from the derived class.
8. Destructors cannot have accessibility modifiers.

No comments: