开发者

C# - class access modificators

开发者 https://www.devze.com 2023-02-08 09:14 出处:网络
Does C# allow the following 开发者_如何学Cthing: Let\'s say I\'ve got namespace X and namespace X.Y.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消