Reputation: 22814
Does C#
allow the following thing:
Let's say I've got namespace X
and namespace X.Y
.
How do I make my class MyClass
in namespace X.Y
internal to that namespace, so that MyClass
couldn't be accessed from namespace X
?
Upvotes: 1
Views: 392
Reputation: 37660
depending of you classes, you can also use nested types. It's possible only if classes in X.Y are only used by one class in X.
Upvotes: 0
Reputation: 33920
The internal
keyword makes a class "private" to the world outside an assembly, yet public to all types within the same assembly.
By placing namespace X
and namespace X.Y
in two separate assemblies, you can have classes in the latter namespace that is internal
to that assembly and thus not accessible to types in the other namespace.
Note: just to underline the fact: there is no way you can make types internal to a namespace, you can only make them internal to an assembly. One assembly may contain internal types in both namespaces and these will be accessible to all types in that assembly, regardless of namespace. Another assembly, also containing types in both namespaces, will only be able to access the public types in the other assembly, regardless of namespace.
Upvotes: 9
Reputation: 2804
Only if you split things up into assemblies i believe.
http://www.eggheadcafe.com/articles/20030111.asp
Upvotes: 0