Does C#
allow the following 开发者_如何学Cthing:
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
?
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.
Only if you split things up into assemblies i believe.
http://www.eggheadcafe.com/articles/20030111.asp
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.
精彩评论