c# - Using nested namespaces -


this question has answer here:

given following namespace structures:

namespace { public static class myclass { public static int myint; } } namespace a.a1 { public static class myclass { public static int myint; } }  namespace b { namespace b1 { public static class myclass { public static int myint; } } } 

why following behaviour?

namespace c {     using a;     using b;      public class someclass {         public void foo() {             // valid, renders 'using' directives obsolete             a.a1.myclass.myint = 5;             b.b1.myclass.myint = 5;              // error: type or namespace a1/b1 not found.             a1.myclass.myint = 5;             b1.myclass.myint = 5;         }     } }  namespace d {     using a.a1;     using b.b1;      public class someclass {         public void bar() {         // valid, renders 'using' directives obsolete         a.a1.myclass.myint = 5;         b.b1.myclass.myint = 5;          // error: myclass ambiguous (of course)         myclass.myint = 5;          // error: type or namespace a1/b1 not found.         a1.myclass.myint = 5;         }     } } 

i had believed using periods in namespace have same effect nesting (ie namespace a.a1 { } == namespace { namespace a1 { } }), , using directive allow me omit portion in future uses. not case?

from using directive page:

create using directive use types in namespace without having specify namespace. a using directive not give access namespaces nested in namespace specify.

you can't wanted.

to give simpler example:

using system;  public class foo {     public void bar()     {         // compilation error!         // need new system.collections.generic.list<int>();         new collections.generic.list<int>();     } } 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -