C # (12) Namespaces)

Source: Internet
Author: User

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 ());
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.