.NET Technical bits: Access Specifiers in C#

Monday, April 5, 2010

Access Specifiers in C#

Public - The type or member can be accessed by any other code in the same assembly or another assembly that references it.

Private - The type or member can only be accessed by code in the same class or struct.

Protected – The type or member can only be accessed by code in the same class or struct, or in a derived class.

Internal – The type or member can be accessed by any code in the same assembly, but not from another assembly.

Protected internal - The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly. The protected internal accessibility means protected OR internal, not protected AND internal. In other words, a protected internal member is accessible from any class in the same assembly, including derived classes. To limit accessibility to only derived classes in the same assembly, declare the class itself internal, and declare its members as protected.

No comments:

Post a Comment