What is the difference between add your imports inside the NameSpace or Outside. Is there a difference in the way assemblies are loaded?
Using System;
namespace test
{
}
VS
namespace test
{
using System;
}
-
Nope.
using
directive is absolutely a compile time thing. It will not affect the runtime behavior in anyway. It just help you not write the long fully qualified type names. -
Putting the the using statement inside the namespace makes it local to that namespace, outside the namespace means anything in the file can reference it. The complier will always search the inner most namespace first.
Stylecop promotes putting the "using" statement inside the namespace and Microsoft claims that placing the using statement inside the namespace allows the CLR to lazy load at runtime. However there is a number of tests that have questioned 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 }
strager : Will System2 be referencable in another file if the test2 namespace is defined in that file (without the using)? -
It's all just a way to get a name to 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 another place..
using Barfaces = Foo.Bar.Interfaces; using Batfaces = Foo.Bar.Interfaces; class A : Barfaces.Iface { }
0 comments:
Post a Comment