可能性の重複:
Should Usings be inside or outside the namespace'using'は名前空間内か外部にあるべきですか?
代わりにデフォルト
using System;
using System.IO;
namespace Foo
{
可能性の重複:
Should Usings be inside or outside the namespace'using'は名前空間内か外部にあるべきですか?
代わりにデフォルト
using System;
using System.IO;
namespace Foo
{
Eric Lippert explains this。
一般に、それらは同じです。
しかし、名前空間のusing
文は、名前空間の外に含まれる名前空間とエイリアスを見ることができます。
namespace Foo
{
using System;
using System.IO;
を好むための技術的な理由があります
技術的な理由はありません。もちろん、コードの2番目のチャンクはきれいに見えます。
ほとんどの場合*同じファイルで複数の名前空間を使用した場合(または同じ名前空間を複数回使用した場合)は、ほとんど違いがあります。
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
}
}
を* SLaks'の答えを参照してください:私は、なぜあなたは確かにすることができ府、ということだろうかわかりません。
これは、拡張メソッドのために有用です。 http://blog.slaks.net/2011/07/creating-local-extension-methods.html – SLaks
http://stackoverflow.com/questions/125319/should-usings-be-inside-or-outside-the-namespaceを参照してください。 – chrisaut
これは双方向で動作しますが、一般的に人々は名前空間の外でそれを好むが、 [名前空間内部または外部の使用](http://stackoverflow.com/questions/125319/should-usings-be-inside-or-outside-the-namespace) –