C# access modifier for exposing class only within namespace

There is no such access modifier: the closest modifier is internal, but the unit of protection is the assembly in which the class resides, not its namespace.

One could argue that it is possible to achieve similar level of control using internal, because both kinds of restriction keep outsiders from accessing the implementation details of your library. The only person to whom it makes a difference is you, the writer of the library, and you are in full control of what to expose and what to hide anyway. Essentially, it means that if you do not want to use a class outside its namespace, simply refrain from using it; if the class is internal, nobody else will be able to use that class either.

Leave a Comment