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#?
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
Namespace collision occurs if parts of the namespace delivered by different people have the same names. For example, two vendors might come up with the same library name and install in the same directory.
Prominent examples for namespaces include file systems, which assign names to files. Some programming languages organize their variables and subroutines in namespaces. Computer networks and distributed systems assign names to resources, such as computers, printers, websites, and remote files.
Namespace is a feature added in C++ and is not present in C. A namespace is a declarative region that provides a scope to the identifiers (names of functions, variables or other user-defined data types) inside it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With