Should “use” be inside the namespace or outside?

Possible duplicate:
If use should be inside or outside the namespace

Are there any technical reasons to prefer this?

namespace Foo { using System; using System.IO; 

instead of the standard

 using System; using System.IO; namespace Foo { 
+7
source share
3 answers

Eric Lippert explains this .

In general, they are identical.
However, using statements in the namespace can see namespaces and aliases included outside the namespace.

+7
source

Almost * the only difference between them would be if you used more than one namespace in one file (or if you used the same namespace more than once). I'm not sure why you are doing this, of course, you 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.

+2
source

No technical reason, just preference. Of course, the second piece of code looks cleaner.

0
source

All Articles