From what I understand, the global:: qualifier allows you to access a namespace that has been hidden by another with the same name. The MSDN page uses System as an example. If you create your own namespace System, you can reach the original with global::System. The first thing that came to mind is, why would anyone call their namespace System?? The page goes on to say this is obviously not recommended, but namespace duplication is very possible in large projects. If/when this does occur, is it a sign that things are heading in the wrong direction, or are there valid reasons to have conflicting namespaces?
From what I understand, the global:: qualifier allows you to access a namespace that
Share
One legitimate reason for having conflicting namespaces might be the use of in-house libraries that were written for earlier versions of .Net that didn’t contain functionality that was added in later versions. In the .Net 1.1 days, for example, I wrote a Registry class that wrapped API registry calls. By pure chance, the method names that I chose were exactly the same as those in the later .Net Registry class, and they did exactly the same things, so it was easy to unplug my homegrown code. For more complicated stuff, being able to use an older, poorly-named chunk of code with the
global::qualifier could be useful.Intentionally naming a new piece of code using an existing .Net namespace would definitely be a code smell, however.