Members of the nested namespace

Assuming it is namespace A2nested in namespace A1, then it A2is a member of the inclusion A1. But the members A2(thus declared in A2) are not members A1.

a) What specifically means that members A2are not members A1? In other words, what would be different if they were also members A1? Is it possible that inside A1we would not need to use the full name for the types defined in A2?

b) What exactly means that the namespace A2is a member A1?

BTW - I understand namespaces, I'm just confused by the terminology used by my book (namely, A2 is a member from A1, etc.)

thank

EDIT

1) Thus, essentially A2being a member A1, is the reason that inside A1we do not need to specify A1. prefixwhen referring to types declared in A2:

namespace A1
{
    class Program
    {
        static void Main(string[] args)
        {
            A2.classA2 a2= A2.classA2(); //here we don't need to include A1.
                                           prefix
        }
    }

    namespace A2
    {
       class classA2 { }
    }
}

2) In assembly asmLibrary.dll

The following are defined:
namespace A
{
    public class A1{}


    namespace B
    {
        public class B1{}
    }
}

The following appendix App1also has a link to the assembly asmLibrary.dll:

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            B.B1 instanceB1 = new B.B1();
        }
    }
}

The following application App2has a link to the assembly asmLibrary.dll:

using A;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            A.B.B1 bInstance = new A.B.B1(); 

            A1 a1 = new A1();
        }
    }
}

a) When we tried to declare to an App2instance A.B.B1, we needed to specify the full name of the type. But App1we were allowed to specify the type through B.B1. Thus, why were we allowed to omit the prefix A.inside App1, but not inside App2(it App2has a directive using A;, so its behavior should be identical to that App1)?

b) , namespace B namespace A, App2 A.B.B1 B.B1 instanceB1 = new B.B1();?!

+3
4

namespace A1
{
    namespace A2  // A1.A2
    {
        class C2  // full name: A1.A2.C2
        {
            private A1.C1 c1b;   // full name 
            private C1 c1b;      // shortest form. A1 is in scope here
        }
    }

    class C1   // full name: A1.C1
    {
        private A1.A2.C2 c2a;   // full name
        private A2.C2 c2b;      // shortest form. We can omit the A1 prefix but not A2
    }
}

a) C2 () A1, A2 A2.C2 c2b;

b) A1 A2, . C1 c1b;


Re Edit:

using a; ... namespace A { ... }.

using A (& sect; 16.3.2) ' App2 .
"" .

+3

A2 A2 - " ". A1 A2, - , A1.member A2 A1.A2.member - using, , .

+1
  • , A2 A1?

#, 3.4:

. , , ".". , .

. [...]

" " 3.4.1:

[...]

, , .

  • A2, A1?

, , A1.A2.Foo , , A1.Foo.

+1

, IL . ; , Customer MyCompany.MyProduct - MyCompany$MyProduct$Customer IL. IL ; , $, .

.: -)

+1
source

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


All Articles