Global keyword in C,

Source: Internet
Author: User

Global keyword in C,

The global keyword is the literal meaning, global.

In fact, sometimes you may make some mistakes, that is, the class name is the same as the system class name. In fact, this is a design mistake, but there may be a situation where it is not changed, then the global keyword plays a role.

The following code:

1 using System;
2 using System. Collections. Generic;
3 using System. Linq;
4 using System. Text;
5
6 namespace globalFunc
7 {
8 class Program
9 {
10 static void Main (string [] args)
11 {
12 System sys = new System ();
13 global: System. Console. WriteLine ("global .");
14 global: System. Console. ReadKey ();
15}
16}
17 public class System {}
18}

Although using has a System namespace, there is also a public class System {...} in this case, if you directly use System. console. writeLine reports an error because the nearest System class is found, so there is no Console in this System class. Therefore, if you need to use global: System. console. writeLine, because the class marked with global will start to look for globally, and my understanding is that it will gradually look for the System class from the outermost surface.

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.