In C #, is it more efficient to use fully qualified names against the 'using' directive?

In C #, when you add a usingdirective for a namespace, it gives you access to all types in that particular namespace. However, if the namespace has many types and I only need one specific one, I often just use the full name, thinking that I don’t want to provide any unnecessary classes that I know I won’t use (especially if there are a lot of them in this namespace) for performance reasons . I thought there had to be some kind of performance impact (no matter how minutes) to make them available, not not, but how much? (if there really is one). And if so, then it would be bad practice to do this everywhere, because will it not begin to accumulate to something remarkable (clever in performance)?

I saw another SO post about using the usingvs full qualified directive , but that doesn't apply to performance.

+5
source share
4 answers

A directive usingis just syntactic sugar that disappears at compile time. Regardless of whether the namespace was included through usingor indicated in a fully qualified type name, this is absolutely not related to the bytecode received. Therefore, at run time, there is no performance advantage when using one or the other.

+16
source

There is no difference.

(.., , ) / ( msbuild), IL , , . , .

+7

, . IL-, .

+3

.

Using the using directive allows you to write code faster. But if you have, for example, 2 namespaces in which you use the using directive, which have methods that have the same name, and also have the same signature, you will run into problems.

Using full qualified help can make your code more understandable.

0
source

All Articles