Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does `Using Namespace;` consume more memory?

Does Using Namespace; consume more memory?

I'm currently working on a mobile application and I was just curious if those unneeded using statements that visual studio places when creating a class make my application require some extra memory to run.

like image 833
Sergio Avatar asked Feb 17 '09 18:02

Sergio


2 Answers

To put it simply: no.

Those statements aren't translated into any form of IL. They're just shortcuts to avoid using (ugly!) fully qualified type names. But, if you're using VS2008 and/or R# you can remove unused ones automagically.

like image 172
R. Martinho Fernandes Avatar answered Oct 05 '22 00:10

R. Martinho Fernandes


Namespaces are a compile-time only feature of C# that allow you to save time during development. The using directives are utilized by the compiler to look up shorthand Type names in your code.

Basically each time the compiler encounters a type name in your code that it does not know it takes each using directive and prepends it to the type's name and sees if that fully qualified name resolves.

Once you application is compiled the namespaces and the using directives are gone as the IL does not need them.

like image 43
Andrew Hare Avatar answered Oct 05 '22 01:10

Andrew Hare