Prev | Current Page 369 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"


7.4 Namespace aliases
Namespaces are simply ways of keeping fully qualified names of types distinct even when
the unqualified names may be the same. An example of this is the unqualified name
Button. There are two classes with that name in the .NET 2.0 Framework: System.
Windows.Forms.Button and System.Web.UI.WebControls.Button. Although they??™re
both called Button, it??™s easy to tell them apart by their namespaces. This mirrors real life
quite closely??”you may know several people called Jon, but you??™re unlikely to know anyone
else called Jon Skeet. If you??™re talking with friends in a particular context, you may
well be able to just use the name Jon without specifying exactly which one you??™re talking
about??”but in other contexts you may need to provide more exact information.
The using directive of C# 1 (not to be confused with the using statement that calls
Dispose automatically) was available in two flavors??”one created an alias for a
194 CHAPTER 7 Concluding C# 2: the final features
namespace or type (for example, using Out = System.Console;) and the other just
introduced a namespace into the list of contexts the compiler would search when
looking for a type (for example, using System.IO;). By and large, this was adequate,
but there are a few situations that the language simply couldn??™t cope with, and others
where automatically generated code would have to go out of its way to make absolutely
sure that the right namespaces and types were being used whatever happened.


Pages:
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381