Question

In C#, is it more efficient from a memory management perspective to use a typed namespace or to include the whole namespace?

For example:

using mySpace.someLogic;

public class Foo
{
 public void Bar()
 {
  doSomethingFromsomeLogic();
 }
}

versus

public class Foo
{
 public void Bar()
 {
  mySpace.someLogic.doSomething();
 }
}

Is one way more efficient? If the answer is "it depends", then what does it depend on?

This question is similar Does including an entire namespace slow things down?, but asks about speed and I am more concerned about memory.

Was it helpful?

Solution

It makes no difference - this is totally personal preference. The compiler will work the same against either style. If, during compilation, it determines you're not using the reference it won't be included.

Related to your question, Visual Studio has tools to clean up and remove unused references.

OTHER TIPS

It slows you down as a programmer, which is more important than slowing the computer down.

It makes no difference in the resulting compiled code, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top