Chapter 13

Additional OOP Techniques

WHAT YOU WILL LEARN IN THIS CHAPTER

  • What the : : operator is
  • What the global namespace qualifier is
  • How to create custom exceptions
  • How to use events
  • How to use anonymous methods
  • How to use C# attributes

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

You can find the wrox.com code downloads for this chapter at www.wrox.com/remtitle.cgi?isbn=9781118314418 on the Download Code tab. The code is in the Chapter 13 download and individually named according to the names throughout the chapter.

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 — it’s 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 might 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 ...

Get Beginning Visual C# 2012 Programming 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.