Global Namespace in C#

By default if you do not specify a namespace for a class it will go to default namespace. What happens When you are in particular namespace that has the same class that is also available in default namespace. How do you access the class that is available in default namespace. With C# 2.0, global keyword was introduced which allows you to access class that is available in global namespace. Here is an example that illustrates the problem and how we use global to access class available in global namespace.

image

image

In the above code when I create an instance of person object and called toString on it, we are confirmed that the instance of person we created resides in Custom namespace because instantiation also happens in Custom namespace. If you wanted to create an instance of Person object in global namespace, we make use of global keyword in front to tell the compiler to create an instance of person object available in global namespace.

3 Comments

Comments have been disabled for this content.