Global: System *** namespace alias qualifier in C #

Source: Internet
Author: User

UsingSystem;

ClassTestapp
{
// Define a new class called 'system' to cause
Problems.
Public ClassSystem {}

// Define a constant called 'console' to cause more
Problems.
Const IntConsole = 7;
Const IntNumber =
66;

Static VoidMain ()
{
// Error accesses testapp. Console
// Console. writeline (number );
}
}

BecauseTestapp. SystemHidden
SystemNamespace, so use
System. ConsoleIt will still cause errors:

// Error accesses
Testapp. System
System. Console. writeline (number );

However, you can useGlobal: system. Console
Avoid this error as follows:

Global: system. Console. writeline (number );

Obviously, it is not recommended to create your own nameSystem
You cannot encounter anyCode. However, in a large project, there may be repeated namespaces in one form or other forms. In this case, the global namespace qualifier ensures that you can specify the root namespace.

Global is C #2.0.
In theory, if the code is well written, it is not required at all.

Suppose you have written a class named system. Then, when you write System in the code
The compiler does not know whether you are writing the system class or the system namespace.
The namespace is already the root namespace and cannot be specified by a full name restriction. In the previous C # version, this is an unsolved problem. Now, you can use

Global: SystemTo indicate System
Root namespace,

And use your ownMynamespace. System
To represent your own class.

Of course, this should not happen. You should not write a class named system.

From: http://www.cnblogs.com/distance/archive/2011/04/20/2022202.html

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.