Chapter 13. Additional OOP Techniques
WHAT YOU WILL LEARN IN THIS CHAPTER
What the
::
operator isWhat the global namespace qualifier is
How to create custom exceptions
How to use events
How to use anonymous methods
In this chapter, you continue exploring the C# language by looking at a few bits and pieces that haven't quite fit in elsewhere. This isn't to say that these techniques aren't useful—just that they don't fall under any of the headings you've worked through so far.
You also make some final modifications to the CardLib code that you've been building in the last few chapters, and even use CardLib to create a card game.
THE :: OPERATOR AND THE GLOBAL NAMESPACE QUALIFIER
The ::
operator provides an alternative way to access types in namespaces. This may be necessary if you want to use a namespace alias and there is ambiguity between the alias and the actual namespace hierarchy. If that's the case, then the namespace hierarchy is given priority over the namespace alias. To see what this means, consider the following code:
using MyNamespaceAlias = MyRootNamespace.MyNestedNamespace; namespace MyRootNamespace { namespace MyNamespaceAlias { public class MyClass {
} } namespace MyNestedNamespace { public class MyClass { } } }
Code in MyRootNamespace
might use the following to refer to a class:
MyNamespaceAlias.MyClass
The class referred to by this code is the MyRootNamespace.MyNamespaceAlias.MyClass
class, not the MyRootNamespace.MyNestedNamespace.MyClass
class. That is, the namespace MyRootNamespace.MyNamespaceAlias ...
Get Beginning Visual C# 2010 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.