0

I have read all those questions on why you should use 'using's inside/outside namespaces and also why you should use or not 'var'.

And I am not looking to have an answer on those here.

What I want to know (or confirm) is: Is there a difference between the two declaration below?

namespace MyCo.MyProject.MyModule
{
   using MyModule2;
   /*Put class definition here*/
}

namespace MyCo.MyProject.MyModule
{
   using MyCo.MyProject.MyModule2;
   /*Put class definition here*/
}

So what is the difference between using fully qualified names for namespaces in using directives and not using them?

I don't think there is any, but if someone can give me a reference I can show to prove (or if I am wrong disprove it (is disprove really an English word or I am making things up?)) this, it would be fantastic.

Sebastien
  • 1,308
  • 2
  • 15
  • 39

1 Answers1

2

Namespaces are there to separate responsibility between different areas of programmatic concern. It means you can have classes and components named the same in the different areas in the application, removing the need for arbitrary names that might confuse users about what they do and their context.

In your example, it is valid to provide the complete namespace but you don't need to, since you are already in the 'area' in which the class can be found. Normally to keep things tidy you would use a using statement at the top of the file to bring in the relevant namespaces you want. Only if class names conflict would actually specify the namespace or a portion of it, in order to differentiate the two.

Ross Miller
  • 656
  • 3
  • 9