Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is referencing a method/variable in an external namespace more memory efficient than including it entirely?

Tags:

c#

So is the following equivalent in memory usage?

System.Threading.Thread.Sleep(500);

vs

using System.Threading;
...
Thread.Sleep(500);

I would have thought that the less namespaces you're 'using' in memory the better, but I've heard that the former example has to load the namespace into memory regardless. I know Sleep isn't the best example of a memory hungry method but it's just an example.

like image 453
Nick Devereaux Avatar asked Jan 26 '26 21:01

Nick Devereaux


1 Answers

The using statement doesn't cause anything at all to be loaded, it only tells the compiler where to look for classes.

The two examples produces exactly the same code.

like image 153
Guffa Avatar answered Jan 29 '26 10:01

Guffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!