Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Csharp Cookbook
Nội dung xem thử
Mô tả chi tiết
[ Team LiB ]
• Table of Contents
• Index
• Reviews
• Reader Reviews
• Errata
• Academic
C# Cookbook
By Jay Hilyard, Stephen Teilhet
Publisher: O'Reilly
Pub Date: January 2004
ISBN: 0-596-00339-0
Pages: 800
The C# Cookbook offers a definitive collection of solutions and examples for this new programming
language. Recipes range from simple tasks to the more complex, and are organized with respect to
the types of problems you'll need to solve as you progress in your experience as a C# programmer.
Nearly every recipe contains a complete, documented code sample showing you how to solve the
specific problem, as well as a discussion of how the underlying technology works and a discussion
of alternatives, limitations, and other considerations where appropriate.
[ Team LiB ]
[ Team LiB ]
• Table of Contents
• Index
• Reviews
• Reader Reviews
• Errata
• Academic
C# Cookbook
By Jay Hilyard, Stephen Teilhet
Publisher: O'Reilly
Pub Date: January 2004
ISBN: 0-596-00339-0
Pages: 800
The C# Cookbook offers a definitive collection of solutions and examples for this new programming
language. Recipes range from simple tasks to the more complex, and are organized with respect to
the types of problems you'll need to solve as you progress in your experience as a C# programmer.
Nearly every recipe contains a complete, documented code sample showing you how to solve the
specific problem, as well as a discussion of how the underlying technology works and a discussion
of alternatives, limitations, and other considerations where appropriate.
[ Team LiB ]
[ Team LiB ]
• Table of Contents
• Index
• Reviews
• Reader Reviews
• Errata
• Academic
C# Cookbook
By Jay Hilyard, Stephen Teilhet
Publisher: O'Reilly
Pub Date: January 2004
ISBN: 0-596-00339-0
Pages: 800
Dedication
Copyright
Preface
Who This Book Is For
What You Need to Use This Book
How This Book Is Organized
What Was Left Out
Conventions Used in This Book
About the Code
Using Code Examples
Platform Notes
Comments and Questions
Acknowledgments
Chapter 1. Numbers
Recipe 1.1. Determining Approximate Equality Between a Fraction and Floating-Point Value
Recipe 1.2. Converting Degrees to Radians
Recipe 1.3. Converting Radians to Degrees
Recipe 1.4. Using the Bitwise Complement Operator with Various Data Types
Recipe 1.5. Test for an Even or Odd Value
Recipe 1.6. Obtaining the Most- or Least-Significant Bits of a Number
Recipe 1.7. Converting a Number in Another Base to Base10
Recipe 1.8. Determining Whether a String Is a Valid Number
Recipe 1.9. Rounding a Floating-Point Value
Recipe 1.10. Different Rounding Algorithms
Recipe 1.11. Converting Celsius to Fahrenheit
Recipe 1.12. Converting Fahrenheit to Celsius
Recipe 1.13. Safely Performing a Narrowing Numeric Cast
Recipe 1.14. Finding the Length of Any Three Sidesof a Right Triangle
Recipe 1.15. Finding the Angles of a Right Triangle
Chapter 2. Strings and Characters
Recipe 2.1. Determining the Kind of Character
Recipe 2.2. Determining Whether a Character Is Within a Specified Range
Recipe 2.3. Controlling Case Sensitivity when Comparing Two Characters
Recipe 2.4. Finding All Occurrences of a Character Within a String
Recipe 2.5. Finding the Location of All Occurrencesof a String Within Another String
Recipe 2.6. The Poor Man's Tokenizer
Recipe 2.7. Controlling Case Sensitivity when Comparing Two Strings
Recipe 2.8. Comparing a String to the Beginning or End of a Second String
Recipe 2.9. Inserting Text into a String
Recipe 2.10. Removing or Replacing Characters Within a String
Recipe 2.11. Encoding Binary Data as Base64
Recipe 2.12. Decoding a Base64-Encoded Binary
Recipe 2.13. Converting a String Returned as a Byte[ ] Back into a String
Recipe 2.14. Passing a String to a Method that Accepts Only a Byte[ ]
Recipe 2.15. Converting Strings to Their Equivalent Value Type
Recipe 2.16. Formatting Data in Strings
Recipe 2.17. Creating a Delimited String
Recipe 2.18. Extracting Items from a Delimited String
Recipe 2.19. Setting the Maximum Number of Characters a String Can Contain
Recipe 2.20. Iterating Over Each Character in a String
Recipe 2.21. Improving String Comparison Performance
Recipe 2.22. Improving StringBuilder Performance
Recipe 2.23. Pruning Characters from the Headand/or Tail of a String
Chapter 3. Classes and Structures
Recipe 3.1. Creating Union-Type Structures
Recipe 3.2. Allowing a Type to Represent Itself as a String
Recipe 3.3. Converting a String Representation of an Object into an Actual Object
Recipe 3.4. Polymorphism via Concrete or Abstract Base Classes
Recipe 3.5. Making a Type Sortable
Recipe 3.6. Making a Type Searchable
Recipe 3.7. Indirectly Overloading the +=, -=, /=, and *= Operators
Recipe 3.8. Indirectly Overloading the &&, ||, and ?: Operators
Recipe 3.9. Improving the Performance of a Structure's Equals Method
Recipe 3.10. Turning Bits On or Off
Recipe 3.11. Making Error-Free Expressions
Recipe 3.12. Minimizing (Reducing) Your Boolean Logic
Recipe 3.13. Converting Between Simple Types in a Language Agnostic Manner
Recipe 3.14. Determining Whether to Use theCast Operator, the as Operator, or theis Operator
Recipe 3.15. Casting with the as Operator
Recipe 3.16. Determining a Variable's Type with the is Operator
Recipe 3.17. Polymorphism via Interfaces
Recipe 3.18. Calling the Same Method on Multiple Object Types
Recipe 3.19. Adding a Notification Callback Using an Interface
Recipe 3.20. Using Multiple Entry Points toVersion an Application
Recipe 3.21. Preventing the Creation of an Only Partially Initialized Object
Recipe 3.22. Returning Multiple Items from a Method
Recipe 3.23. Parsing Command-Line Parameters
Recipe 3.24. Retrofitting a Class to Interoperate with COM
Recipe 3.25. Initializing a Constant Field at Runtime
Recipe 3.26. Writing Code that Is Compatible with the Widest Range of Managed Languages
Recipe 3.27. Implementing Nested foreach Functionality in a Class
Recipe 3.28. Building Cloneable Classes
Recipe 3.29. Assuring an Object's Disposal
Recipe 3.30. Releasing a COM Object ThroughManaged Code
Recipe 3.31. Creating an Object Cache
Recipe 3.32. The Single Instance Object
Recipe 3.33. Choosing a Serializer
Recipe 3.34. Creating Custom Enumerators
Recipe 3.35. Rolling Back Object Changes
Recipe 3.36. Disposing of Unmanaged Resources
Recipe 3.37. Determining Where Boxing and Unboxing Occur
Chapter 4. Enumerations
Recipe 4.1. Displaying an Enumeration Value as a String
Recipe 4.2. Converting Plain Text to an Equivalent Enumeration Value
Recipe 4.3. Testing for a Valid Enumeration Value
Recipe 4.4. Testing for a Valid Enumeration of Flags
Recipe 4.5. Using Enumerated Members in a Bitmask
Recipe 4.6. Determining Whether One or More Enumeration Flags Are Set
Chapter 5. Exception Handling
Recipe 5.1. Verifying Critical Parameters
Recipe 5.2. Indicating Where Exceptions Originate
Recipe 5.3. Choosing when to Throw a Particular Exception
Recipe 5.4. Handling Derived Exceptions Individually
Recipe 5.5. Assuring Exceptions are Not Lost when Using Finally Blocks
Recipe 5.6. Handling Exceptions Thrown from Methods Invoked via Reflection
Recipe 5.7. Debugging Problems whenLoading an Assembly
Recipe 5.8. HRESULT-Exception Mapping
Recipe 5.9. Handling User-Defined HRESULTs
Recipe 5.10. Preventing Unhandled Exceptions
Recipe 5.11. Displaying Exception Information
Recipe 5.12. Getting to the Root of a Problem Quickly
Recipe 5.13. Creating a New Exception Type
Recipe 5.14. Obtaining a Stack Trace
Recipe 5.15. Breaking on a First Chance Exception
Recipe 5.16. Preventing the Nefarious TypeInitializationException
Recipe 5.17. Handling Exceptions Thrown from an Asynchronous Delegate
Chapter 6. Diagnostics
Recipe 6.1. Controlling Tracing Output inProduction Code
Recipe 6.2. Providing Fine-Grained Control Over Debugging/Tracing Output
Recipe 6.3. Creating Your Own Custom Switch Class
Recipe 6.4. A Custom Trace Class that Outputs Information in an XML Format
Recipe 6.5. Conditionally Compiling Blocks of Code
Recipe 6.6. Determining Whether a Process Has Stopped Responding
Recipe 6.7. Using One or More Event Logs in Your Application
Recipe 6.8. Changing the Maximum Size of a Custom Event Log
Recipe 6.9. Searching Event Log Entries
Recipe 6.10. Watching the Event Log for a Specific Entry
Recipe 6.11. Finding All Sources Belonging to a Specific Event Log
Recipe 6.12. Implementing a Simple Performance Counter
Recipe 6.13. Implementing Performance Counters that Require a Base Counter
Recipe 6.14. Enable/Disable Complex Tracing Code
Chapter 7. Delegates and Events
Recipe 7.1. Controlling when and if a Delegate Fires Within a Multicast Delegate
Recipe 7.2. Obtaining Return Values from Each Delegate in a Multicast Delegate
Recipe 7.3. Handling Exceptions Individually for Each Delegate in a Multicast Delegate
Recipe 7.4. Converting a Synchronous Delegate to an Asynchronous Delegate
Recipe 7.5. Adding Events to a Sealed Class
Recipe 7.6. Passing Specialized Parameters to and from an Event
Recipe 7.7. An Advanced Interface Search Mechanism
Recipe 7.8. An Advanced Member Search Mechanism
Recipe 7.9. Observing Additions and Modifications to a Hashtable
Recipe 7.10. Using the Windows Keyboard Hook
Recipe 7.11. Using Windows Hooks to Manipulate the Mouse
Chapter 8. Regular Expressions
Recipe 8.1. Enumerating Matches
Recipe 8.2. Extracting Groups from a MatchCollection
Recipe 8.3. Verifying the Syntax of a Regular Expression
Recipe 8.4. Quickly Finding Only the Last Match in a String
Recipe 8.5. Replacing Characters or Words in a String
Recipe 8.6. Augmenting the Basic String Replacement Function
Recipe 8.7. A Better Tokenizer
Recipe 8.8. Compiling Regular Expressions
Recipe 8.9. Counting Lines of Text
Recipe 8.10. Returning the Entire Line in Which a Match Is Found
Recipe 8.11. Finding a Particular Occurrence of a Match
Recipe 8.12. Using Common Patterns
Recipe 8.13. Documenting Your Regular Expressions
Chapter 9. Collections
Recipe 9.1. Swapping Two Elements in an Array
Recipe 9.2. Quickly Reversing an Array
Recipe 9.3. Reversing a Two-Dimensional Array
Recipe 9.4. Reversing a Jagged Array
Recipe 9.5. A More Flexible StackTrace Class
Recipe 9.6. Determining the Number of Times an Item Appears in an ArrayList
Recipe 9.7. Retrieving All Instances of a Specific Itemin an ArrayList
Recipe 9.8. Inserting and Removing Items from an Array
Recipe 9.9. Keeping Your ArrayList Sorted
Recipe 9.10. Sorting a Hashtable's Keys and/or Values
Recipe 9.11. Creating a Hashtable with Max and Min Size Boundaries
Recipe 9.12. Creating a Hashtable with Max and Min Value Boundaries
Recipe 9.13. Displaying an Array's Data as a Delimited String
Recipe 9.14. Storing Snapshots of Lists in an Array
Recipe 9.15. Creating a Strongly Typed Collection
Recipe 9.16. Persisting a Collection Between Application Sessions
Chapter 10. Data Structures and Algorithms
Recipe 10.1. Creating a Hash Code for a Data Type
Recipe 10.2. Creating a Priority Queue
Recipe 10.3. Creating a More Versatile Queue
Recipe 10.4. Determining Where Characters or Strings Do Not Balance
Recipe 10.5. Creating a One-to-Many Map (MultiMap)
Recipe 10.6. Creating a Binary Tree
Recipe 10.7. Creating an n-ary Tree
Recipe 10.8. Creating a Set Object
Chapter 11. Filesystem I/O
Recipe 11.1. Creating, Copying, Moving, and Deleting a File
Recipe 11.2. Manipulating File Attributes
Recipe 11.3. Renaming a File
Recipe 11.4. Determining Whether a File Exists
Recipe 11.5. Choosing a Method of Opening a File or Stream for Reading and/or Writing
Recipe 11.6. Randomly Accessing Part of a File
Recipe 11.7. Outputting a Platform-Independent EOL Character
Recipe 11.8. Create, Write to, and Read from a File
Recipe 11.9. Determining Whether a Directory Exists
Recipe 11.10. Creating, Moving, and Deleting a Directory
Recipe 11.11. Manipulating Directory Attributes
Recipe 11.12. Renaming a Directory
Recipe 11.13. Searching for Directories or FilesUsing Wildcards
Recipe 11.14. Obtaining the Directory Tree
Recipe 11.15. Parsing a Path
Recipe 11.16. Parsing Paths in Environment Variables
Recipe 11.17. Verifying a Path
Recipe 11.18. Using a Temporary File in Your Application
Recipe 11.19. Opening a File Stream with just aFile Handle
Recipe 11.20. Write to Multiple Output Files at One Time
Recipe 11.21. Launching and Interacting withConsole Utilities
Recipe 11.22. Locking Subsections of a File
Recipe 11.23. Watching the Filesystem for Specific Changes to One or More Files or Directories
Recipe 11.24. Waiting for an Action to Occurin the Filesystem
Recipe 11.25. Comparing Version Information of Two Executable Modules
Chapter 12. Reflection
Recipe 12.1. Listing Imported Assemblies
Recipe 12.2. Listing Exported Types
Recipe 12.3. Finding Overridden Methods
Recipe 12.4. Finding Members in an Assembly
Recipe 12.5. Finding Members Within an Interface
Recipe 12.6. Obtaining Types Nested Within a Type
Recipe 12.7. Displaying the Inheritance Hierarchy for a Type
Recipe 12.8. Finding the Subclasses of a Type
Recipe 12.9. Finding All Serializable Types Within an Assembly
Recipe 12.10. Controlling Additions to an ArrayList Through Attributes
Recipe 12.11. Filtering Output when Obtaining Members
Recipe 12.12. Dynamically Invoking Members
Chapter 13. Networking
Recipe 13.1. Converting an IP Address to a Hostname
Recipe 13.2. Converting a Hostname to an IP Address
Recipe 13.3. Parsing a URI
Recipe 13.4. Forming an Absolute URI
Recipe 13.5. Handling Web Server Errors
Recipe 13.6. Communicating with a Web Server
Recipe 13.7. Going Through a Proxy
Recipe 13.8. Obtaining the HTML from a URL
Recipe 13.9. Writing a TCP Server
Recipe 13.10. Writing a TCP Client
Recipe 13.11. Simulating Form Execution
Recipe 13.12. Downloading Data from a Server
Recipe 13.13. Using Named Pipes to Communicate
Chapter 14. Security
Recipe 14.1. Controlling Access to Types in aLocal Assembly
Recipe 14.2. Encrypting/Decrypting a String
Recipe 14.3. Encrypting and Decrypting a File
Recipe 14.4. Cleaning Up Cryptography Information
Recipe 14.5. Verifying that a String Is Uncorrupted During Transmission
Recipe 14.6. Wrapping a String Hash for Ease of Use
Recipe 14.7. A Better Random Number Generator
Recipe 14.8. Securely Storing Data
Recipe 14.9. Making a Security Assert Safe
Recipe 14.10. Preventing Malicious Modifications to an Assembly
Recipe 14.11. Verifying that an Assembly Has Been Granted Specific Permissions
Recipe 14.12. Minimizing the Attack Surface of an Assembly
Chapter 15. Threading
Recipe 15.1. Creating Per-Thread Static Fields
Recipe 15.2. Providing Thread Safe Access to Class Members
Recipe 15.3. Preventing Silent Thread Termination
Recipe 15.4. Polling an Asynchronous Delegate
Recipe 15.5. Timing Out an Asynchronous Delegate
Recipe 15.6. Being Notified of the Completionof an Asynchronous Delegate
Recipe 15.7. Waiting for Worker Thread Completion
Recipe 15.8. Synchronizing the Reading and Writingof a Resource Efficiently
Recipe 15.9. Determining Whether a Requestfor a Pooled Thread Will Be Queued
Recipe 15.10. Waiting for All Threads in theThread Pool to Finish
Recipe 15.11. Configuring a Timer
Recipe 15.12. Storing Thread-Specific Data Privately
Chapter 16. Unsafe Code
Recipe 16.1. Controlling Changes to Pointers Passedto Methods
Recipe 16.2. Comparing Pointers
Recipe 16.3. Navigating Arrays
Recipe 16.4. Manipulating a Pointer to a Fixed Array
Recipe 16.5. Returning a Pointer to a Particular Element in an Array
Recipe 16.6. Creating and Using an Array of Pointers
Recipe 16.7. Creating and Using an Array of Pointersto Unknown Types
Recipe 16.8. Switching Unknown Pointer Types
Recipe 16.9. Breaking Up Larger Numbers into Their Equivalent Byte Array Representation
Recipe 16.10. Converting Pointers to a Byte[ ], SByte[ ],or Char[ ] to a String
Chapter 17. XML
Recipe 17.1. Reading and Accessing XML Datain Document Order
Recipe 17.2. Reading XML on the Web
Recipe 17.3. Querying the Contents of an XML Document
Recipe 17.4. Validating XML
Recipe 17.5. Creating an XML Document Programmatically
Recipe 17.6. Detecting Changes to an XML Document
Recipe 17.7. Handling Invalid Characters in anXML String
Recipe 17.8. Transforming XML to HTML
Recipe 17.9. Tearing Apart an XML Document
Recipe 17.10. Putting Together an XML Document
Colophon
Index
[ Team LiB ]
[ Team LiB ]
Dedication
To my mom, dad, and my brother Justin, thanks for all your help, support, and guidance.
—Stephen
To Brooke, thank you for everything. I love you and couldn't have done this without you.
—Jay
[ Team LiB ]
[ Team LiB ]
Copyright
Copyright © 2004 O'Reilly & Associates, Inc.
Printed in the United States of America.
Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O'Reilly & Associates books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://safari.oreilly.com). For more information,
contact our corporate/institutional sales department: (800) 998-9938 or [email protected].
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of
O'Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks. Where those designations appear in this
book, and O'Reilly & Associates, Inc. was aware of a trademark claim, the designations have been
printed in caps or initial caps. The Cookbook series designations, C# Cookbook, the image of a
garter snake, and related trade dress are trademarks of O'Reilly & Associates, Inc.
While every precaution has been taken in the preparation of this book, the publisher and authors
assume no responsibility for errors or omissions, or for damages resulting from the use of the
information contained herein.
[ Team LiB ]
[ Team LiB ]
Preface
C# is a language targeted at developers for the Microsoft .NET platform who have already worked
with a C-like language such as C, C++, or Java. Unlike previous versions of C or C++ for the
Microsoft Windows platform, C# code runs under a managed execution environment. While C and
C++ developers using Visual Studio .NET can now write managed code using the Managed
Extensions for C++, C# offers a middle path between C++'s overall power but sometimes difficult
code and the higher-level task orientation provided by Visual Basic .NET. Microsoft portrays C# as
a modern and innovative language for .NET development that will be familiar to current C++
programmers while allowing more runtime control over the executing code.
C# allows you to perform many C/C++-like functions such as direct memory access via pointers
and operator overloading that are not supported in Visual Basic .NET. Many of the interesting
enhancements for .NET languages are slated to appear first in C#, such as generics. (You can think
of generics as templates with a twist.) C# is the system-level programming language for .NET. You
can still do great application-level work in C#, but it really shines when you need to build code a
little closer to the framework.
If you have seen C#, you may have noticed that it looks a lot like Java; Java programmers will feel
very much at home in C# once they learn the Framework SDK. C# can also be a great language for
Visual Basic .NET programmers when they need a little more control over what the code is doing
and don't want to have to write C++ to gain an advantage. There is a large community on the Web
of people doing really neat things with C# and there is tons of sample code on sites such as
http://www.gotdotnet.com, http://www.codeproject.com, and http://www.4guysfromrolla.com.
We put this book together based on programming problems we ran into when first learning C# as
well as during our continued use of it. We hope that it will help you get past some of the common
(and not-so-common) pitfalls and initial questions everyone has when learning a new language.
There are recipes dealing with things we found missing from the .NET Framework Class Library
(FCL), even though Microsoft has provided tons of functionality to keep folks from reinventing the
wheel. Some of these solutions you might immediately use and some may never darken your door,
but we hope this book helps you get the most out of C# and the .NET Framework.
The book is laid out with respect to the types of problems you will solve as you progress through
your life as a C# programmer. These solutions are called recipes; each recipe consists of a single
problem, its solution, a discussion of the solution and other relevant related information, and finally
where you can look for more information about the classes used from the FCL, other books
addressing this topic, related articles, and other recipes. The question-answer format provides
complete solutions to problems, making the book easy to read and use. Nearly every recipe
contains a complete, documented code sample showing you how to solve the specific problem, as
well as a discussion of how the underlying technology works and a list of alternatives, limitations,
and other considerations, when appropriate.
[ Team LiB ]
[ Team LiB ]
Who This Book Is For
You don't have to be an experienced C# or .NET developer to use this book—it is designed for users
of all levels. This book provides solutions to problems that developers face every day as well as
some that may come along infrequently. The recipes are targeted at the real-world developer who
needs to solve problems now, not learn lots of theory first before being able to solve the problem.
While reference or tutorial books can teach general concepts, they do not generally provide the
help you need in solving real-world problems. We chose to teach by example, the natural way for
most people to learn.
The majority of the problems addressed in this book are frequently faced by C# developers, but
some of the more advanced problems call for more intricate solutions that combine many
techniques. Each recipe is designed to help you quickly understand the problem, learn how to solve
it, and find out any potential tradeoffs or ramifications to help you solve your problems quickly,
efficiently, and with minimal effort.
To save you even the effort of typing in the solution, we provide the sample code for the book on
the O'Reilly web site to facilitate the "editor inheritance" mode of development (copy and paste) as
well as to help less experienced developers see good programming practice in action. The sample
code provides a running test harness that exercises each of the solutions, but enough of the code is
provided in each solution in the book to allow you to implement the solution without the sample
code. The sample code is available from the book's catalog page:
http://www.oreilly.com/catalog/csharpckbk.
[ Team LiB ]
[ Team LiB ]
What You Need to Use This Book
To run the samples in this book, you need a computer running Windows 2000 or later (if you are
using Windows NT 4.0, you can use many, but not all, of the examples in this book; in particular,
ASP.NET and .NET web services do not run on NT 4.0). A few of the networking and XML solutions
require Microsoft Internet Information Server (IIS) Version 5 or later.
To open and compile the samples in this book, you need Visual Studio .NET 2003. If you are
proficient with the downloadable Framework SDK and its command-line compilers, you should not
have any trouble following the text of this book and the code samples.
[ Team LiB ]
[ Team LiB ]
How This Book Is Organized
This book is organized into seventeen chapters, each of which focuses on a particular topic in
creating C# solutions. The following paragraphs summarize each chapter to give you an overview
of this book's contents:
Chapter 1
This chapter focuses on the numeric data types used in C# code. Recipes cover such things as
numeric conversions, using bitwise operators on numbers, and testing strings to determine
whether they contain a numeric value.
Chapter 2
This chapter covers both the String data type as well as the Char data type. Various recipes
show how to compare strings in various ways, encode/decode strings, break strings apart,
and put them back together again, to name a few.
Chapter 3
This large chapter contains recipes dealing with both class and structure data types. This
chapter covers a wide range of recipes from design patterns to converting a class to
interoperating with COM.
Chapter 4
This chapter covers the enum data type. Recipes display, convert and test enumeration types.
In addition, there are recipes on using enumerations that consist of bit flags.
Chapter 5
The recipes in this chapter focus on the best ways to implement exception handling in your
application. Preventing unhandled exceptions, reading and displaying stack traces, and
throwing/rethrowing exceptions are included recipes. In addition, specific recipes show how
to overcome some tricky situations, such as exceptions from late-bound called methods.