Wednesday, June 28, 2017

The global namespace in C#!

var x = new global::Walrus(); varies from var y = new Walrus(); in that the first will look for Walrus in the global namespace which is the project-wide globally available stuff that exists when you do not wrap a class declaration in a using directive. Think extension methods. Obviously if you need something out of the global namespace and it has a name conflict with something in the immediate namespace it will be tricky to call. You cannot lead the type with dot, dot, dot to give the namespace, right? Instead, use this hacky thing.

No comments:

Post a Comment