3

I don't know why Asp.net MVC developers put the using directives inside System.Web.Mvc namespace as follows.

namespace System.Web.Mvc
{
    using System;
    using System.Collections.ObjectModel;

    [Serializable]
    public class ModelErrorCollection : Collection<ModelError>
    {

        public void Add(Exception exception)
        {
            Add(new ModelError(exception));
        }

        public void Add(string errorMessage)
        {
            Add(new ModelError(errorMessage));
        }
    }
}

When do we need to put using directives inside a namespace scope?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
LaTeX
  • 1,411
  • 1
  • 17
  • 37
  • 2
    I don't know if it's even necessary. The only reason I could think of that might require that is if you have a source file that has multiple namespaces within it. But how often to people _really_ do that? Not a lot I hope. – Jeff Mercado Feb 17 '11 at 05:59

2 Answers2

3

See Should 'using' statements be inside or outside the namespace?

Community
  • 1
  • 1
C.Evenhuis
  • 25,996
  • 2
  • 58
  • 72
2

It's your choice. StyleCop tool warns of it as a best practice, however Visual Studio generated files always have usings outside namespace.

Should all the using directives for namespaces be inside the namespace?

Community
  • 1
  • 1
Artem Koshelev
  • 10,548
  • 4
  • 36
  • 68