Using namespaces and loading

What is the difference between adding imports inside NameSpace or Outside. Is there any difference in loading assemblies?

Using System;
namespace test
{

}
VS
namespace test
{
using System;

}
+3
source share
3 answers

Putting the using statement inside the namespace makes it local to this namespace, outside the namespace means that everything in the file can refer to it. Complexity will always look for an internal namespace.

Stylecop helps put the using statement in the namespace, and Microsoft claims that placing the using statement inside the namespace allows the CLR to be lazy at run time. However, there are a number of tests that cast doubt on this .

Using System;
namespace test
{
  //Can Ref System
}

namespace test2
{
    using System2;
    //can Reference anything from test2, System2 and System   
    //will look for a reference in test, then System2 then System


}
+7

. using - . . .

+1

This is just a way to get a name for an object. You can even rename some things if you start getting conflicts:

/// buncha assys.
namespace Foo.Bar.Interfaces { interface Iface { }; }
namespace Foo.Baz.Interfaces { interface Iface { }; }
namespace Foo.Bat.Interfaces { interface Iface { }; }

In the other place..

using Barfaces = Foo.Bar.Interfaces;
using Batfaces = Foo.Bar.Interfaces;

class A : Barfaces.Iface { }
0
source

Source: https://habr.com/ru/post/1705120/


All Articles