"using namespace" means loading integer types in that namespace

Say I have a code

using System; using System.Windows.Forms; class TestApp { static void Main() { Console.WriteLine("Testing! 1, 2, 3"); MessageBox.Show("Hello..."); } } 

will the tags using System and System.Windows.Forms load all types (inside these namespaces) at run time, although im will only be used for printing on the console and display a message box?

and it will also use memory to load the necessary types ( Console and MessageBox ) at runtime ...

[and there will be some block of code (inside the Console ) that is still not used by the source code, but will still be loaded? ]

so any hint about what happens behind the scenes (at least for above 10 lines of code) will be helpful ...

+4
source share
2 answers
Operators

using are only compile-time operators that allow the compiler to find reference types without specifying a full name each time they are used; they will not load anything at runtime that otherwise would not load if it were to refer directly to the same type.

+7
source

Yes, all types are directly in the namespace, so none of the subspace namespaces. This means that with repeated use, compilation time * increases. But this does not affect the runtime, because by that time there were no more applications, and every use of the namespace was converted to a direct reference to the type.

* This means the part that says "loading characters", and in fact, this does not always need to be done. Thus, a great solution at my work takes 30 seconds to load all the characters, but most compilers run very fast because you don't have to reload the characters.

edit @xCoder: This is due to how the assembly works, there are no classes, just data. Thus, classes in which you use a higher-level language are compiled into different assembler codes, because the class processes data differently. C # uses IL instead of assembly, and I'm not sure, but it probably works the same way.

0
source

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


All Articles