Prev | Current Page 370 | Next

Jon Skeet

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


C# 2 fixes these problems, bringing an additional robustness to the language. It??™s
not that the code being generated is any more robust in terms of execution, but you
can write code that is guaranteed to mean what you want it to regardless of which
other types, assemblies, and namespaces are introduced. These extreme measures are
rarely needed outside automatically generated code, but it??™s nice to know that they??™re
there when you need them. In C# 2 there are three types of aliases: the namespace
aliases of C# 1, the global namespace alias, and extern aliases. We??™ll start off with the one
type of alias that was already present in C# 1, but we??™ll introduce a new way of using
aliases to ensure that the compiler knows to treat it as an alias rather than checking to
see whether it??™s the name of another namespace or type.
7.4.1 Qualifying namespace aliases
Even in C# 1, it was a good idea to avoid namespace aliases wherever possible. Every so
often you might find that one type name clashed with another??”as with our Button
example earlier??”and so you either had to specify the full name including the
namespace every time you used them, or have an alias that distinguished the two, in
some ways acting like a shortened form of the namespace. Listing 7.5 shows an example
where the two types of Button are used, qualified by an alias.
using System;
using WinForms = System.


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