Should 'using' be inside the namespace or outside?
Possible Duplicate:
Should Usings be inside or outside the namespace
Are there any technical reasons for preferring this
namespace Foo
{
using System;
using System.IO;
instead of the default
using System;
using System.IO;
namespace Foo
{
Eric Lippert explains this.
In general, they're identical.
However, using
statements in the namespace can see namespaces and aliases included outside the namespace.
Almost* the only difference between the two would be if you used more than one namespace in the same file (or if you used the same namespace more than once). I'm not sure why would you do that, bu you certainly can:
using System;
namespace FooNamespace
{
using System.IO;
class Foo
{
// you can use types from System and System.IO directly here
}
}
namespace BarNamespace
{
class Bar
{
// you can't use types from System.IO directly here
// but you can use types from System
}
}
* See SLaks' answer.
No technical reason, just a preference. of course the second chunk of code looks cleaner, though.
链接地址: http://www.djcxy.com/p/21066.html上一篇: 在函数重复字符串或字符在.NET中?
下一篇: “使用”应该放在命名空间还是外部?