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

2.3k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER
0
On

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?