O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Aliases

The using directive can be extended with the definition of a named alias, acting as an abbreviation for the namespace or type name on the right side. An example of this is shown in Chapter 22, “Dynamic Programming,” when dealing with the Word and Excel automation APIs. In this context, the Application type exists in both namespaces used for Word and Excel interop. Use of an alias allowed us to abbreviate references to them:

using Word  = Microsoft.Office.Interop.Word;using Excel = Microsoft.Office.Interop.Excel;

Now we can write the following two lines of code, disambiguating a reference to the Application interface:

var excel = new Excel.Application();var word  = new Word.Application();

Defined aliases ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required