Namespace alias operator - the :: is used to access a member of an aliased namespace. - C# reference (original) (raw)

Use the namespace alias qualifier :: to access a member of an aliased namespace. You can use the :: qualifier only between two identifiers. The left-hand identifier can be one of a namespace alias, an extern alias, or the global alias. For example:

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);  
}  
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 . token to access a member of an aliased namespace. However, the . token is also used to access a type member. 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