开发者

Namespaces and Sub-Namespaces and the libraries they reference in C#

Can I have

namespace somenamespace
{
//references functionality in DLL_1
      namespace somesubnamespace
      {
       //references functionality in DLL_2
      }
}

And if I do this, when I use just somenamespace, will it only include DLL_1 in the solution and if I use somenamespace.somesubnamespace will it include DLL_1 and DLL_2 in the solu开发者_JS百科tion?

Or are DLL_1 and DLL_2 set on the project that contains the namespace and no matter which I use, both DLLs will be copied?


You only need to add references to the DLLs that your code actually uses (directly or indirectly).

Therefore, if library X has two classes that reference library A and B respectively, and you only use the class that references library A, you do not need library B at all.

Namespaces are organizational concepts and have nothing to do with it.


Your code above is exactly equivalent to:

namespace.somesubnamespace
{

}

If you write it your way, or if you write it this way, accessing somesubnamespace is done exactly the same way in your code.

Namespaces are essentially just labels to organize your code. Depending on what your code is accessing will dictate what references you need - but the answer to your question is "no", the references for namespace will not necessarily be required. namespace.somesubnamespace is an independent namespace in that regard.


If you add references to the DLLs, they will be copied. Since you must add the reference in order to use them, both will always be copied.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜