Jump to content
Wikibooks The Free Textbook Project

C# Programming/Keywords/global

From Wikibooks, open books for an open world
The latest reviewed version was checked on 16 April 2020. There are template/file changes awaiting review.

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:

namespaceMyApp
{
publicstaticclassSystem
{
publicstaticvoidMain()
{
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:

publicstaticclassSystem
{
publicstaticvoidMain()
{
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 (Contextual Keywords)
Contextual Keywords (Used in Queries)

AltStyle によって変換されたページ (->オリジナル) /