Note that there are some explanatory texts on larger screens.

plurals
  1. POMembers of a nested namespace
    primarykey
    data
    text
    <p>Assuming <code>namespace A2</code> is nested within <code>namespace A1</code>, then <code>A2</code> is a member of enclosing <code>A1</code>. But members of <code>A2</code> ( thus types declared within <code>A2</code> ) are not members of <code>A1</code>. </p> <p>a) What exactly is meant by members of <code>A2</code> not being members of <code>A1</code>? In other words, what would be different if they were also members of <code>A1</code>? Perhaps that inside <code>A1</code> we wouldn’t have to use fully qualified name for types in defined in <code>A2</code>? </p> <p>b) What exactly is it meant by namespace <code>A2</code> being a member of <code>A1</code>? </p> <p>BTW - I do understand namespaces, I'm just confused by the terminology used by my book ( namely, A2 being a <strong>member</strong> of A1 etc )</p> <p>thanx</p> <p><strong>EDIT</strong></p> <p>1) So essentially <code>A2</code> being a member of <code>A1</code> is the reason why inside <code>A1</code> we don't have to specify <code>A1. prefix</code> when referencing types declared in <code>A2</code>:</p> <pre><code>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 { } } } </code></pre> <p>2) The following is defined within <code>assembly asmLibrary.dll</code></p> <pre><code>namespace A { public class A1{} namespace B { public class B1{} } } </code></pre> <p>The following application <code>App1</code> also has a reference to assembly <code>asmLibrary.dll</code>:</p> <pre><code>namespace A { class Program { static void Main(string[] args) { B.B1 instanceB1 = new B.B1(); } } } </code></pre> <p>The following application <code>App2</code> has a reference to assembly <code>asmLibrary.dll</code>:</p> <pre><code>using A; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { A.B.B1 bInstance = new A.B.B1(); A1 a1 = new A1(); } } } </code></pre> <p>a) When we tried to declare in <code>App2</code> an instance of <code>A.B.B1</code>, we needed to specify fully qualified name of the type. But with <code>App1</code> we were allowed to specify the type via <code>B.B1</code>. Thus why were we allowed to ommit the <code>A.</code> prefix inside <code>App1</code>, but not inside <code>App2</code> ( <code>App2</code> has a <code>using A;</code> directive, so its behaviour should be identical to that of <code>App1</code> )?</p> <p>b) Also, if <code>namespace B</code> is a member of <code>namespace A</code>, shouldn't then <code>App2</code> allow us to declare a type <code>A.B.B1</code> using <code>B.B1 instanceB1 = new B.B1();</code> syntax?!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload