C Sharp Programming/Keywords/global
From Wikibooks, the open-content textbooks collection
The global keyword is useful in some contexts to resolve ambiguity between identifiers. If you have a conflict between a class name and a namespace, for example, you can use the global keyword to access the namespace:
namespace MyApp { public static class System { public static void Main() { global::System.Console.WriteLine("Hello, world!"); // if we had just used System.Console.WriteLine, // the compile would think that we referred to a // class named "Console" inside our "System" class. } } }
global does not work in the following situation, however, as our System class does not have a namespace:
public static class System { public static void Main() { global::System.Console.WriteLine("Hello, world!"); // "System" doesn't have a namespace, so the above // would be referring to this class! } }
| C# Keywords | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Special C# Identifiers | ||||||||||
|