Namespace conflict in C#
There is a System
namespace inside my program's namespace. And as a result I can't see the standard System
namespace from within mine. How can I resolve this problem?
For example in C++ there is the ::
operator which 'shifts' me out of my namespace, so I can see external namespaces with the same name as my current namespace:
Is there a similar operator in C#?
You need to use the global
keyword. That forces the namespace resolution to start at the very top. It's mostly used in generated code to be doubly sure the right namespace is referenced.
global::System.Foo.Bar;
Some MSDN documentation on it: http://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx
For more convenience, you can give it an alias, too:
using GSystem = global::System;
Will allow you to refer to the global System
namespace as GSystem
or whatever else you would like to call it.
yes
global::System
Strange though that you are getting a conflict with system.
Nothing should declare that namespace except system itself....
You can use global
精彩评论