C # details about namespace

Source: Internet
Author: User

<1> The namespace hierarchy takes precedence over the namespace alias.
If this alias is the same as an existing namespace, you can use ":" to try the alias, which limits the alias namespace to be called.

using MyNamespace = ConsoleApplication19Namespace.MyNamespace2;namespace ConsoleApplication19Namespace{    class Program    {        static void Main(string[] args)        {            MyNamespace.Myclass My = new MyNamespace.Myclass();            My.print();            MyNamespace::Myclass You = new MyNamespace::Myclass();            You.print();        }    }    namespace MyNamespace    {        class Myclass        {            public void print()            {                Console.WriteLine("This is in the ConsoleApplication.MyNamespace.Myclass");            }        }    }    namespace MyNamespace2    {        class Myclass        {            public void print()            {                Console.WriteLine("This is in the ConsoleApplication.MyNamespace2.Myclass");            }        }    }}


Output:
This is in the ConsoleApplication. MyNamespace. Myclass
This is in the ConsoleApplication. MyNamespace2.Myclass


<2> global namespace
Global and ":" use the alias of the top-level root namespace together with globale:. Calling the top-level root namespace can prevent external variables or external classes from being internal variables, the appearance of hidden internal classes.
For example:
Global: System. Console. WriteLine ("what a fuck day"); // No problem occurs.


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.