Namespaces and Using Directives

JL. picture JL. · Jul 21, 2009 · Viewed 8.9k times · Source

If I have a namespace like:

namespace MyApp.Providers
 {
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Globalization;
  }

Does this mean that if I create other files and classes with the same namespace, the using statements are shared, and I don't need to include them again?

If yes, isn't this a bit of a management headache?

Answer

Brandon picture Brandon · Jul 21, 2009

No, it's only good for the namespace section inside the file. Not for all files inside the namespace.

If you put the using statement outside the namespace, then it applies to the entire file regardless of namespace.

It will also search the Usings inside the namespace first, before going to the outer scope.