简体   繁体   English

包括在名称空间中使用

[英]including using in namespace

I have been wondering what is better way of using code. 我一直在想什么是使用代码的更好方法。 Is there any difference between writing using inside of namespace: 使用命名空间内部进行编写之间有什么区别:

ouside of namespace 命名空间的替代

using System.Data.Entity;
using System.Web.Mvc;
using System.Web.Routing;
using Myproject.DataLayer;


namespace Myproject
{
  public class MyProjectClass{
  // etc
  }
}

Inside of namespace the only reason i can thing of : shorter names, and the complier does not need to go to global location to find the implementation... but not sure about the rest 在名称空间中,我唯一能想到的原因是:较短的名称,并且编译器不需要转到全局位置来查找实现...但是不确定其余部分

namespace Myproject
{
using System.Data.Entity;
using System.Web.Mvc;
using System.Web.Routing;
using DataLayer;

  public class MyProjectClass{
  // etc
  }
}

Scott have already answered the question at http://www.hanselman.com/blog/BackToBasicsDoNamespaceUsingDirectivesAffectAssemblyLoading.aspx Scott已经在http://www.hanselman.com/blog/BackToBasicsDoNamespaceUsingDirectivesAffectAssemblyLoading.aspx上回答了问题

Value of keeping the using code & Alias names inside namespace incase if you decide to have multiple namespaces in one file. 如果您决定在一个文件中有多个名称空间,则在名称空间中保留使用代码和别名的价值。

But the question to ask yourself is why do I want to have multiple namespace's in the same file 但是要问自己的问题是为什么我要在同一个文件中拥有多个命名空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM