Importing Namespaces
In C#, the way to import namespaces is by means of the using
directive. As a result, instead of having to use fully qualified type names, you can refer to types by a shorter name. Leveraging using directives simply affects the name resolution carried out by the compiler. At runtime, types are always referred to by fully qualified names, as you saw before in Figure 24.4.
The using
directives are scoped to the immediately enclosing compilation unit (that is, code file) or the namespace declaration in which they’re contained. For example, given the following code, you can refer to types in the System
namespace directly:
using System;namespace Contoso.CashFlow.Client{ class Program { static ...
Get C# 5.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.