KennyH
KennyH

Reputation: 773

Access Modifier for Namespace

Can a function or sub-routine be accessed by the same namespace with the access modifier of private?

Or does the access modifier need to be public or internal?

Upvotes: 3

Views: 5162

Answers (2)

G.M.
G.M.

Reputation: 87

Clearifying MSDN content about http://msdn.microsoft.com/en-us/library/ba0a1yw2.aspx

Upvotes: -1

Mike Parkhill
Mike Parkhill

Reputation: 5551

Within a class you can access all methods and properties that belong to that class as well as any protected members exposed by its base class (if it has one).

Within another class in the same namespace assembly (or friend assembly) you can only reference the public or internal members of the first class.

Classes from other namespaces assemblies can only access public members.

Notes:

  • namespaces are syntactic sugar provided by C#/VB, the real boundary for accessing internal methods is on assembly level. Namespaces by themselves have no visibility rules, nor change visibility of any entities.
  • namespaces can span multiple assemblies and multiple namespaces can be in the same assembly.

Upvotes: 3

Related Questions