1.12 Namespaces)
We have spent a lot of ink on namespace before (I forgot how to connect it! O. K. Please read it later ). We once said "I not
Like the hello world ". However, it will be very tiring to be often said in the program. If you want to use it in other code, it will be more complicated, then you can use
Namespace. The code for opening the first example is as follows :*/
Namespace MyOpinion
{
Public class Message
{
Public string GetMessage (){
Return "I dont like Hello world ";
}
}
}
/*
If I want to use namespace to create a library, I need to classify my custom functions and classes and fill in the corresponding namespace.
For example :*/
Namespace Mylib. Csharp. MyOpinion
{
Public class Message
{
Public string GetMessage (){
Return "I dont like Hello world ";
}
}
}
/*
Namespace is classified, and "Mylib. Csharp. MyOpinion" is short for it. The namespace after each "." is included in the package
Include. If split :*/
Namespace Mylib
{
Namespace Csharp
{
Namespace MyOpinion
{....}
}
}
/*
Then, we can use our own database :*/
Using Mylib. Csharp. MyOpinion;
Class test
{
Static void Main (){
Message m = new Message ();
System. Console. WriteLine (m. GetMessage ());
}
}
/*
However, no matter how careful we are, there will be duplicate names, that is, name conflicts. In this case, the alias can be used. For example, the code above can be as follows :*/
Using MessageSource = Mylib. Csharp. MyOpinion;
Class test
{
Static void Main (){
MessageSource m = new MessageSource ();
System. Console. WriteLine (m. GetMessage ());
}
}