Occasionally two different assemblies define a type with the same fully-qualified name (same namespace and class name). In C# 1.0 there was no way to reference both types in the same file - one would always shadow the other.
C# 2.0 introduces extern alias which lets you assign a named alias to an assembly reference. You can then use the alias as a root namespace to disambiguate between the two types.
Code
C#
extern alias Vendor1;
extern alias Vendor2;
Vendor1::Acme.Logging.Logger v1Logger = new Vendor1::Acme.Logging.Logger();
Vendor2::Acme.Logging.Logger v2Logger = new Vendor2::Acme.Logging.Logger();C#
// Not possible to reference both types - one will always shadow the other
// Must restructure code to avoid using both assemblies in the same fileNotes
- The alias is assigned to the assembly reference in the project file or via the
/rcompiler switch (e.g./r:Vendor1=Vendor1.Logging.dll) - The
globalalias always refers to the default global namespace - This is rarely needed but essential when it is, particularly when working with multiple versions of the same library