Namespace declaration:
UseNamespaceA keyword is used to declare a namespace. The namespace declaration cannot contain any access modifiers. Declaring a namespace can help control the range of class names and method names to prevent name conflicts.
Namespaces can be nested.
For example:
Namespace
{
Namespace B
{
}
}
Namespace A. B
{
}
The two are equivalent.
Namespace reference:
Use the using command to import the namespace or use a fully qualified name. In most cases, you can use using. But how can I cause a compilation error when two namespaces have the same class name,
In this case, you need to use a fully qualified name. Another way is to use using to create an alias for the namespace.
For example:
Declare two namespaces with the same class Test.
Namespace
{
Public class Test
{
}
}
Namespace B
{
Public class Test
{
}
}
Only use a namespace class. You can use the using command or use a fully qualified name.
For example:
Using;
Namespace C
{
Class Program
{
Static void Main (string [] args)
{
Test a = new Test (); // equivalent to the fully qualified name A. Test A = new A. Test ();
}
}
}
If you use both the Test classes of the namespace A and B, the following error occurs: "Test" is an ambiguous reference between "A. Test" and "B. Test ".
Using;
Using B;
Namespace C
{
Class Program
{
Static void Main (string [] args)
{
Test a = new Test ();
}
}
}
In this case, use the fully qualified name to use the class Test.
Using;
Using B;
Namespace C
{
Class Program
{
Static void Main (string [] args)
{
A. Test a = new A. Test ();
}
}
}
In this way, no error is reported.