In other words, does the following make a difference:
this:
using a;
using b;
using c;
public class foo {
public void doStuff() {
// do some stuff utilizing classes from a, b, and c.
}
}
Versus this:
public class foo {
public void doStuff() {
bar.doStuff();
}
}
together with:
using a;
using b;
using c;
public static class bar {
public static void doStuff() {
// do some stuff utilizing classes from a, b, and c
}
}
Assuming foo is a class that is used and passed around a lot, serialized/deserialized often, etc. However the doStuff() method is called infrequently. Is there any performance advantage at all in breaking it out into the second/third snippets above?
No.
usingis merely about which simple names you can use in the source file in which theusingdeclaration appears.Basically,
using N;says to the compiler “hey, if I type the simple nameFooin this source file, and you can’t find anything namedFooin scope, can you check if there is anything namedFooin the namespaceN?” Thanks!That is, you can leave off the
usingand reference everything by it’s fully-qualified name and you haven’t changed the IL output by the compiler at all.Per the above explanation, no.