:: operator (C# reference)

Use the namespace alias qualifier :: to access members of an aliased namespace. You use the :: qualifier between two identifiers. The left-hand identifier can be any of the following aliases:

  • A namespace alias created with the using alias directive:

    using forwinforms = System.Drawing;
    using forwpf = System.Windows;
    
    public class Converters
    {
        public static forwpf::Point Convert(forwinforms::Point point) => new forwpf::Point(point.X, point.Y);
    }
    
  • An extern alias.

  • The global alias, which is the global namespace alias. The global namespace is the namespace that contains namespaces and types that are not declared inside a named namespace. When used with the :: qualifier, the global alias always references the global namespace, even if there is the user-defined global namespace alias.

    The following example uses the global alias to access the .NET System namespace, which is a member of the global namespace. Without the global alias, the user-defined System namespace, which is a member of the MyCompany.MyProduct namespace, would be accessed:

    namespace MyCompany.MyProduct.System
    {
        class Program
        {
            static void Main() => global::System.Console.WriteLine("Using global alias");
        }
    
        class Console
        {
            string Suggestion => "Consider renaming this class";
        }
    }
    

    Note

    The global keyword is the global namespace alias only when it's the left-hand identifier of the :: qualifier.

You can also use the member access . operator to access members of an aliased namespace. However, the . operator is also used to access members of a type. The :: qualifier ensures that its left-hand identifier always references a namespace alias, even if there exists a type or namespace with the same name.

C# language specification

For more information, see the Namespace alias qualifiers section of the C# language specification.

See also