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