This is a corner case ::
(like the @
prefix) is there to deal with the fairly rare occurrences where a name conflicts between namespaces, classes and keywords.
::
only works for namespaces (and namespace aliases), while .
. works for both namespaces and subclasses. Most places where you'd need it you'd be better off using a different name instead, but that isn't always an option.
global::
is a special case that's most often seen in auto-generated code - it resets the referenced namespace to the root.
For instance, suppose you auto-generate some code (maybe for a forms app, EF, or similar) and your app uses the namespace YourCompany.Application
. Now one of your customers (using your auto-generation) decides to add their own namespace in their app TheirCompany.YourCompany.Application
. Now all your auto code fails because when it compiles .Net doesn't know whether to use your namespace or theirs.
To fix this generate code with global::YourCompany.Application
, then those that use your auto-generator can use whatever namespace they like and not conflict.
I think Microsoft added global::
because they expected some .Net customers to add namespaces like System
.