Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Modifier for Namespace

Tags:

c#

vb.net

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?

like image 915
KennyH Avatar asked Nov 22 '25 11:11

KennyH


1 Answers

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.
like image 91
Mike Parkhill Avatar answered Nov 24 '25 01:11

Mike Parkhill