Like runtime class classes

What happens at runtime when the number of namespaces is used in space? Are classes loaded from namespaces loaded completely or a loaded class? What to do if the program contains unused namespaces?

+4
source share
2 answers

Namespaces are more like a compilation time construct, and then a run-time construct. Putting classes in a namespace primarily affects the class name only. The "full name" of any class is actually its namespace hierarchy (separated by dots . ), Followed by the actual class name. You do not load the namespace at run time, the whole concept does not exist.

When compiling a program, if you compile it into a library (DLL), you can add a link to this .dll, in which case all classes in this DLL will be โ€œaccessibeโ€ in your program. As for whether they will be loaded, it is certainly possible to load them, but the probability of lazy initialization of unused classes will not have a significant impact on performance.

When you add a using statement to the top of a file for a namespace, it does not โ€œloadโ€ that namespace. It will be used by the compiler to resolve all "unskilled" class names to "fully qualified" class names (at compile time). If you used only full class names, you wonโ€™t need using (but it really clutters your code, so you should add them anyway).

+6
source

You can use as many namespaces as you want. Namespaces do not load classes. Think of namespaces as a convenient function, like the path variable. If you are not using namespaces, you will end up writing code like this:

 System.Collections.Generic.List<string> myList = new System.Collections.Generic.List<string>(); 

This would make the code very verbose and tedious in a short time. In using namespaces, you can shorten the code to this:

 using System.Collections.Generic; // ..... further down in code: List<string> myList = new List<string>(); 

The following 2 links can help broaden your understanding of namespaces:

http://msdn.microsoft.com/en-us/library/sf0df423%28v=vs.80%29.aspx

http://msdn.microsoft.com/en-us/library/0d941h9d%28v=vs.80%29.aspx

Bottom line: namespaces will help organize and control the scope for your classes in the project.

NTN ...

+1
source

Source: https://habr.com/ru/post/1444136/


All Articles