.NET命名空间和使用说明 [英] .NET namespaces and using statements

查看:212
本文介绍了.NET命名空间和使用说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/125319/should-usings-be-inside-or-outside-the-namespace">Should Usings的内部或命名空间外

namespace x
{
  using y;
}

using y;
namespace x
{
}

推荐答案

第一种具有的y范围只是命名空间X,第二个有Ÿ范围为整个文件,所以potentialy其他名称空间。如果你把每个文件的一个命名空间(我猜是这样的约定)再有就是的一般的没有真正的区别[但见马克的评论有关冲突如果不同的类型具有相同的名称在不同的命名空间。如果你使用了StyleCop它会要你保持usings命名空间内。

The first one has y in scope for just the namespace x, the second has y in scope for the whole file, so potentialy other namespaces. If you keep to one namespace per file (I'd guess that was the convention) then there's usually no real difference [but see Marc's comment about clashes if different types have the same name in different namespaces]. If you use StyleCop it will want you to keep the usings inside the namespace.

这篇关于.NET命名空间和使用说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆