What is the scope resolution operator in C#?

CsharpProgrammingServer Side Programming

The scope resolution operator in C# has a different meaning as compared with C++. In C++ the :: is used for global variables, whereas in C# it is related to namespaces.

If you have a type that share an identifier in different namespace, then to identify them use the scope resolution operator.

For example, to reference System.Console class, use the global namespace alias with the scope resolution operator.



 Live Demo

using myAlias = System.Collections;
namespace Program {
   class Demo {
      static void Main() {
         myAlias::Hashtable h = new myAlias::Hashtable();
         h.Add("Q", "1");
         h.Add("R", "2");
         h.Add("S", "3");
         h.Add("T", "4");
         h.Add("U", "5");
         foreach (string n in h.Keys) {
            global::System.Console.WriteLine(n + " " + h[n]);


T 4
R 2
S 3
U 5
Q 1
Published on 18-Sep-2018 08:16:01