The Global keyword in C #

Source: Internet
Author: User

The global keyword is literally meant to be the whole world.

In fact, some times will make some mistakes, that is, the class name takes a similar to the system class name situation, in fact, this is a design error, but there will be a situation is not changed, then the global Key has played a role.

The following code:

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;

6 namespace Globalfunc
7 {
8 Class Program
9 {
Ten static void Main (string[] args)
Each {
System sys = new system ();
global::system.console.writeline ("global");
Global::system.console.readkey ();
}
+ }
Public class System {}
18}

While using a System namespace, there is also a public class system{...} class, so that if the direct use of System.Console.WriteLine will be an error, because you will find the nearest system class, then there is no Console in this system class. So if you need to use it, you need to use Global::system.console.writeline, as above, because the class using the global tag will start looking at the world, and my understanding is to look for the System class from the outermost to the inside.

The Global keyword in C #

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.