Reputation: 910
I have seen double colons (::
) in generated code. I was wondering what its purpose is?
Upvotes: 46
Views: 12449
Reputation: 838786
It's the namespace alias qualifier operator. Citing from the linked-to MSDN page:
The namespace alias qualifier (
::
) is used to look up identifiers. It is always positioned between two identifiers, as in this example:global::System.Console.WriteLine("Hello World");
Upvotes: 57
Reputation: 74822
This is the namespace alias qualifier. It's used when there's the potential for two different types with the same name and same namespace (coming from different assemblies). E.g. our ORM product talks to VistaDB 3 and VistaDB 4. In both cases the connection class is VistaDB.Provider.VistaDBConnection. So we extern alias
the VistaDB 3 assembly to vdb3
and the VistaDB 4 assembly to vdb4
and can now disambiguate the connection classes as vdb3::VistaDB.Provider.VistaDBConnection
and vdb4::VistaDB.Provider.VistaDBConnection
. Without the alias qualifier, these would raise "ambiguous reference" compiler errors.
Upvotes: 41