Differences between "use" (import) inside or outside the "namespace"?

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

I saw two approaches to using assemblies. What is the difference and advantages of using one over the other

namespace Assembly 
{
    using System.Data;
    class Foo{
    ...
    }
} 

using System.Data; 
namespace Assembly
{
    class Foo{
    ...
    }   
}
+5
source share
2 answers

In fact, there is a slight difference between them.

Consider the following example:

//File1.cs
using System;
namespace Outer.Inner
{
    class Foo
    {
        static void Bar()
        {
                double d = Math.PI;
        }
    }
}

// File2.cs
namespace Outer
{
    class Math
    {
    }
}

An error will appear in the compiler because it will find the Mathclass in the namespace Outerbefore searching in the namespace System. And inside this namespace is Mathnot PI.

, using System , , .

: , , - Math , , .

( )

0

, . .

0

All Articles