:: Operator and global keyword
Suppose you have defined your own class with name ‘System’ and inside it you want to use the Console class of the .Net System namespace, what will you do?
namespace MyNameSpace { class System { static void Main(string[] args) { System.Console.WriteLine("Hello, world"); System.Console.ReadLine(); } } }
With C# 2.0, you can use the :: operator with global keyword to achieve this. It allows you to access members in the global namespace.
namespace MyNameSpace { class System { static void Main(string[] args) { global:: System.Console.WriteLine("Hello, world"); global:: System.Console.ReadLine(); } } }
It tells the compiler to search for the global namespace named ‘System’.