开发者

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

This question already has answers here: Should 'using' directives be inside or outside the namespace in C#? (13 answers) Closed 8 years ago.

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 sco开发者_StackOverflow中文版pe?


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜