You are previewing C# Cookbook.
O'Reilly logo
C# Cookbook

Book Description

Easy to learn and use, the C# language is targeted at developers for Microsoft's .NET platform who've worked with a C-like language before, such as C, C++, or Java. There's no shortage of excellent tutorials and documentation to help new developers get a handle on the language, such as O'Reilly's Learning C# or Programming C#. But when you need practical answers to the day-to-day questions you run up against, a tutorial isn't going to do the trick. The C# Cookbook gets straight to the heart of the problem with code recipes collected especially for developers working on the .NET platform. 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. The recipes in the C# Cookbook are organized into seventeen chapters, each of which focuses on a particular topic in creating C# solutions. Among the topics covered, you'll find:

  • Numeric data types in C#

  • Strings and characters

  • Classes and structures

  • Exception handling

  • Delegates and events

  • Regular expressions

  • Data structures and algorithms

  • Networking

  • Security

  • Unsafe Code

You don't need to be an experienced C# or .NET developer to use this book. The C# Cookbook is designed for users of all levels with recipes targeted at the real-world developer who needs to solve problems now, not learn lots of theory first. With this guide, all developers will be able to learn and improve their mastery of both the language and the .NET Framework Class Libraries.

Table of Contents

  1. C# Cookbook
    1. Preface
      1. Who This Book Is For
      2. What You Need to Use This Book
      3. How This Book Is Organized
      4. What Was Left Out
      5. Conventions Used in This Book
      6. About the Code
      7. Using Code Examples
      8. Platform Notes
      9. Comments and Questions
      10. Acknowledgments
        1. From Steve Teilhet
        2. From Jay Hilyard
    2. 1. Numbers
      1. 1.1. Determining Approximate Equality Between a Fraction and Floating-Point Value
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 1.2. Converting Degrees to Radians
        1. Problem
        2. Solution
        3. Discussion
      3. 1.3. Converting Radians to Degrees
        1. Problem
        2. Solution
        3. Discussion
      4. 1.4. Using the Bitwise Complement Operator with Various Data Types
        1. Problem
        2. Solution
        3. Discussion
      5. 1.5. Test for an Even or Odd Value
        1. Problem
        2. Solution
        3. Discussion
      6. 1.6. Obtaining the Most- or Least-Significant Bits of a Number
        1. Problem
        2. Solution
        3. Discussion
      7. 1.7. Converting a Number in Another Base to Base10
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 1.8. Determining Whether a String Is a Valid Number
        1. Problem
        2. Solution
        3. Discussion
      9. 1.9. Rounding a Floating-Point Value
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 1.10. Different Rounding Algorithms
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 1.11. Converting Celsius to Fahrenheit
        1. Problem
        2. Solution
        3. Discussion
      12. 1.12. Converting Fahrenheit to Celsius
        1. Problem
        2. Solution
        3. Discussion
      13. 1.13. Safely Performing a Narrowing Numeric Cast
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 1.14. Finding the Length of Any Three Sidesof a Right Triangle
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 1.15. Finding the Angles of a Right Triangle
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    3. 2. Strings and Characters
      1. 2.1. Determining the Kind of Character
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 2.2. Determining Whether a Character Is Within a Specified Range
        1. Problem
        2. Solution
        3. Discussion
      3. 2.3. Controlling Case Sensitivity when Comparing Two Characters
        1. Problem
        2. Solution
        3. Discussion
      4. 2.4. Finding All Occurrences of a Character Within a String
        1. Problem
        2. Solution
        3. Discussion
      5. 2.5. Finding the Location of All Occurrencesof a String Within Another String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 2.6. The Poor Man’s Tokenizer
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 2.7. Controlling Case Sensitivity when Comparing Two Strings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 2.8. Comparing a String to the Beginning or End of a Second String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 2.9. Inserting Text into a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 2.10. Removing or Replacing Characters Within a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 2.11. Encoding Binary Data as Base64
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 2.12. Decoding a Base64-Encoded Binary
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 2.13. Converting a String Returned as a Byte[ ] Back into a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 2.14. Passing a String to a Method that Accepts Only a Byte[ ]
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 2.15. Converting Strings to Their Equivalent Value Type
        1. Problem
        2. Solution
        3. Discussion
      16. 2.16. Formatting Data in Strings
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 2.17. Creating a Delimited String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      18. 2.18. Extracting Items from a Delimited String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      19. 2.19. Setting the Maximum Number of Characters a String Can Contain
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      20. 2.20. Iterating Over Each Character in a String
        1. Problem
        2. Solution
        3. Discussion
      21. 2.21. Improving String Comparison Performance
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      22. 2.22. Improving StringBuilder Performance
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      23. 2.23. Pruning Characters from the Headand/or Tail of a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    4. 3. Classes and Structures
      1. 3.1. Creating Union-Type Structures
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 3.2. Allowing a Type to Represent Itself as a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 3.3. Converting a String Representation of an Object into an Actual Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 3.4. Polymorphism via Concrete or Abstract Base Classes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 3.5. Making a Type Sortable
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 3.6. Making a Type Searchable
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 3.7. Indirectly Overloading the +=, -=, /=, and *= Operators
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 3.8. Indirectly Overloading the &&, ||, and ?: Operators
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 3.9. Improving the Performance of a Structure’s Equals Method
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 3.10. Turning Bits On or Off
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 3.11. Making Error-Free Expressions
        1. Problem
        2. Solution
        3. Discussion
      12. 3.12. Minimizing (Reducing) Your Boolean Logic
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 3.13. Converting Between Simple Types in a Language Agnostic Manner
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 3.14. Determining Whether to Use theCast Operator, the as Operator, or theis Operator
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 3.15. Casting with the as Operator
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 3.16. Determining a Variable’s Type with the is Operator
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 3.17. Polymorphism via Interfaces
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      18. 3.18. Calling the Same Method on Multiple Object Types
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      19. 3.19. Adding a Notification Callback Using an Interface
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      20. 3.20. Using Multiple Entry Points toVersion an Application
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      21. 3.21. Preventing the Creation of an Only Partially Initialized Object
        1. Problem
        2. Solution
        3. Discussion
      22. 3.22. Returning Multiple Items from a Method
        1. Problem
        2. Solution
        3. Discussion
      23. 3.23. Parsing Command-Line Parameters
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      24. 3.24. Retrofitting a Class to Interoperate with COM
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      25. 3.25. Initializing a Constant Field at Runtime
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      26. 3.26. Writing Code that Is Compatible with the Widest Range of Managed Languages
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      27. 3.27. Implementing Nested foreach Functionality in a Class
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      28. 3.28. Building Cloneable Classes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      29. 3.29. Assuring an Object’s Disposal
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      30. 3.30. Releasing a COM Object ThroughManaged Code
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      31. 3.31. Creating an Object Cache
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      32. 3.32. The Single Instance Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      33. 3.33. Choosing a Serializer
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      34. 3.34. Creating Custom Enumerators
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      35. 3.35. Rolling Back Object Changes
        1. Problem
        2. Solution
        3. Discussion
      36. 3.36. Disposing of Unmanaged Resources
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      37. 3.37. Determining Where Boxing and Unboxing Occur
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    5. 4. Enumerations
      1. 4.1. Displaying an Enumeration Value as a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 4.2. Converting Plain Text to an Equivalent Enumeration Value
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 4.3. Testing for a Valid Enumeration Value
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 4.4. Testing for a Valid Enumeration of Flags
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 4.5. Using Enumerated Members in a Bitmask
        1. Problem
        2. Solution
        3. Discussion
      6. 4.6. Determining Whether One or More Enumeration Flags Are Set
        1. Problem
        2. Solution
        3. Discussion
    6. 5. Exception Handling
      1. 5.1. Verifying Critical Parameters
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 5.2. Indicating Where Exceptions Originate
        1. Problem
        2. Solution
        3. Discussion
      3. 5.3. Choosing when to Throw a Particular Exception
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 5.4. Handling Derived Exceptions Individually
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 5.5. Assuring Exceptions are Not Lost when Using Finally Blocks
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 5.6. Handling Exceptions Thrown from Methods Invoked via Reflection
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 5.7. Debugging Problems whenLoading an Assembly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 5.8. HRESULT-Exception Mapping
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 5.9. Handling User-Defined HRESULTs
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 5.10. Preventing Unhandled Exceptions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 5.11. Displaying Exception Information
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 5.12. Getting to the Root of a Problem Quickly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 5.13. Creating a New Exception Type
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 5.14. Obtaining a Stack Trace
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 5.15. Breaking on a First Chance Exception
        1. Problem
        2. Solution
        3. Discussion
      16. 5.16. Preventing the Nefarious TypeInitializationException
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 5.17. Handling Exceptions Thrown from an Asynchronous Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    7. 6. Diagnostics
      1. 6.1. Controlling Tracing Output inProduction Code
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 6.2. Providing Fine-Grained Control Over Debugging/Tracing Output
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 6.3. Creating Your Own Custom Switch Class
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 6.4. A Custom Trace Class that Outputs Information in an XML Format
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 6.5. Conditionally Compiling Blocks of Code
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 6.6. Determining Whether a Process Has Stopped Responding
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 6.7. Using One or More Event Logs in Your Application
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 6.8. Changing the Maximum Size of a Custom Event Log
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 6.9. Searching Event Log Entries
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 6.10. Watching the Event Log for a Specific Entry
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 6.11. Finding All Sources Belonging to a Specific Event Log
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 6.12. Implementing a Simple Performance Counter
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 6.13. Implementing Performance Counters that Require a Base Counter
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 6.14. Enable/Disable Complex Tracing Code
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    8. 7. Delegates and Events
      1. 7.1. Controlling when and if a Delegate Fires Within a Multicast Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 7.2. Obtaining Return Values from Each Delegate in a Multicast Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 7.3. Handling Exceptions Individually for Each Delegate in a Multicast Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 7.4. Converting a Synchronous Delegate to an Asynchronous Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 7.5. Adding Events to a Sealed Class
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 7.6. Passing Specialized Parameters to and from an Event
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 7.7. An Advanced Interface Search Mechanism
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 7.8. An Advanced Member Search Mechanism
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 7.9. Observing Additions and Modifications to a Hashtable
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 7.10. Using the Windows Keyboard Hook
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 7.11. Using Windows Hooks to Manipulate the Mouse
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    9. 8. Regular Expressions
      1. 8.1. Enumerating Matches
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 8.2. Extracting Groups from a MatchCollection
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 8.3. Verifying the Syntax of a Regular Expression
        1. Problem
        2. Solution
        3. Discussion
      4. 8.4. Quickly Finding Only the Last Match in a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 8.5. Replacing Characters or Words in a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 8.6. Augmenting the Basic String Replacement Function
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 8.7. A Better Tokenizer
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 8.8. Compiling Regular Expressions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 8.9. Counting Lines of Text
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 8.10. Returning the Entire Line in Which a Match Is Found
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 8.11. Finding a Particular Occurrence of a Match
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 8.12. Using Common Patterns
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 8.13. Documenting Your Regular Expressions
        1. Problem
        2. Solution
        3. Discussion
    10. 9. Collections
      1. 9.1. Swapping Two Elements in an Array
        1. Problem
        2. Solution
        3. Discussion
      2. 9.2. Quickly Reversing an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 9.3. Reversing a Two-Dimensional Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 9.4. Reversing a Jagged Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 9.5. A More Flexible StackTrace Class
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 9.6. Determining the Number of Times an Item Appears in an ArrayList
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 9.7. Retrieving All Instances of a Specific Itemin an ArrayList
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 9.8. Inserting and Removing Items from an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 9.9. Keeping Your ArrayList Sorted
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 9.10. Sorting a Hashtable’s Keys and/or Values
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 9.11. Creating a Hashtable with Max and Min Size Boundaries
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 9.12. Creating a Hashtable with Max and Min Value Boundaries
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 9.13. Displaying an Array’s Data as a Delimited String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 9.14. Storing Snapshots of Lists in an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 9.15. Creating a Strongly Typed Collection
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 9.16. Persisting a Collection Between Application Sessions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    11. 10. Data Structures and Algorithms
      1. 10.1. Creating a Hash Code for a Data Type
        1. Problem
        2. Solution
          1. The simple hash
          2. The folding hash
          3. The contained object cache
          4. The CryptoHash method
          5. The CryptoHash method using a nonstring
          6. The shift and add hash
          7. The calculated hash
          8. The string concatenation hash
        3. Discussion
        4. See Also
      2. 10.2. Creating a Priority Queue
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 10.3. Creating a More Versatile Queue
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 10.4. Determining Where Characters or Strings Do Not Balance
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 10.5. Creating a One-to-Many Map (MultiMap)
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 10.6. Creating a Binary Tree
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 10.7. Creating an n-ary Tree
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 10.8. Creating a Set Object
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    12. 11. Filesystem I/O
      1. 11.1. Creating, Copying, Moving, and Deleting a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 11.2. Manipulating File Attributes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 11.3. Renaming a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 11.4. Determining Whether a File Exists
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 11.5. Choosing a Method of Opening a File or Stream for Reading and/or Writing
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 11.6. Randomly Accessing Part of a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 11.7. Outputting a Platform-Independent EOL Character
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 11.8. Create, Write to, and Read from a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 11.9. Determining Whether a Directory Exists
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 11.10. Creating, Moving, and Deleting a Directory
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 11.11. Manipulating Directory Attributes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 11.12. Renaming a Directory
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 11.13. Searching for Directories or FilesUsing Wildcards
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      14. 11.14. Obtaining the Directory Tree
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      15. 11.15. Parsing a Path
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      16. 11.16. Parsing Paths in Environment Variables
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      17. 11.17. Verifying a Path
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      18. 11.18. Using a Temporary File in Your Application
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      19. 11.19. Opening a File Stream with just aFile Handle
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      20. 11.20. Write to Multiple Output Files at One Time
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      21. 11.21. Launching and Interacting withConsole Utilities
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      22. 11.22. Locking Subsections of a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      23. 11.23. Watching the Filesystem for Specific Changes to One or More Files or Directories
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      24. 11.24. Waiting for an Action to Occurin the Filesystem
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      25. 11.25. Comparing Version Information of Two Executable Modules
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    13. 12. Reflection
      1. 12.1. Listing Imported Assemblies
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 12.2. Listing Exported Types
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 12.3. Finding Overridden Methods
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 12.4. Finding Members in an Assembly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 12.5. Finding Members Within an Interface
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 12.6. Obtaining Types Nested Within a Type
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 12.7. Displaying the Inheritance Hierarchy for a Type
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 12.8. Finding the Subclasses of a Type
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 12.9. Finding All Serializable Types Within an Assembly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 12.10. Controlling Additions to an ArrayList Through Attributes
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 12.11. Filtering Output when Obtaining Members
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 12.12. Dynamically Invoking Members
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    14. 13. Networking
      1. 13.1. Converting an IP Address to a Hostname
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 13.2. Converting a Hostname to an IP Address
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 13.3. Parsing a URI
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 13.4. Forming an Absolute URI
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 13.5. Handling Web Server Errors
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 13.6. Communicating with a Web Server
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 13.7. Going Through a Proxy
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 13.8. Obtaining the HTML from a URL
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 13.9. Writing a TCP Server
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 13.10. Writing a TCP Client
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 13.11. Simulating Form Execution
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 13.12. Downloading Data from a Server
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      13. 13.13. Using Named Pipes to Communicate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    15. 14. Security
      1. 14.1. Controlling Access to Types in aLocal Assembly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 14.2. Encrypting/Decrypting a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 14.3. Encrypting and Decrypting a File
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 14.4. Cleaning Up Cryptography Information
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 14.5. Verifying that a String Is Uncorrupted During Transmission
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 14.6. Wrapping a String Hash for Ease of Use
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 14.7. A Better Random Number Generator
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 14.8. Securely Storing Data
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 14.9. Making a Security Assert Safe
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 14.10. Preventing Malicious Modifications to an Assembly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 14.11. Verifying that an Assembly Has Been Granted Specific Permissions
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 14.12. Minimizing the Attack Surface of an Assembly
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    16. 15. Threading
      1. 15.1. Creating Per-Thread Static Fields
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 15.2. Providing Thread Safe Access to Class Members
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 15.3. Preventing Silent Thread Termination
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 15.4. Polling an Asynchronous Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 15.5. Timing Out an Asynchronous Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 15.6. Being Notified of the Completionof an Asynchronous Delegate
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 15.7. Waiting for Worker Thread Completion
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 15.8. Synchronizing the Reading and Writingof a Resource Efficiently
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 15.9. Determining Whether a Requestfor a Pooled Thread Will Be Queued
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 15.10. Waiting for All Threads in theThread Pool to Finish
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      11. 15.11. Configuring a Timer
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      12. 15.12. Storing Thread-Specific Data Privately
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    17. 16. Unsafe Code
      1. 16.1. Controlling Changes to Pointers Passedto Methods
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 16.2. Comparing Pointers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 16.3. Navigating Arrays
        1. Problem
        2. Solution
        3. See Also
      4. 16.4. Manipulating a Pointer to a Fixed Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 16.5. Returning a Pointer to a Particular Element in an Array
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 16.6. Creating and Using an Array of Pointers
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 16.7. Creating and Using an Array of Pointersto Unknown Types
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 16.8. Switching Unknown Pointer Types
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 16.9. Breaking Up Larger Numbers into Their Equivalent Byte Array Representation
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      10. 16.10. Converting Pointers to a Byte[ ], SByte[ ],or Char[ ] to a String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
    18. 17. XML
      1. 17.1. Reading and Accessing XML Datain Document Order
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      2. 17.2. Reading XML on the Web
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      3. 17.3. Querying the Contents of an XML Document
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      4. 17.4. Validating XML
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      5. 17.5. Creating an XML Document Programmatically
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      6. 17.6. Detecting Changes to an XML Document
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      7. 17.7. Handling Invalid Characters in anXML String
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      8. 17.8. Transforming XML to HTML
        1. Problem
        2. Solution
        3. Discussion
        4. See Also
      9. 17.9. Tearing Apart an XML Document
        1. Problem
        2. Solution
          1. BillingEnvelope XML
          2. ShippingEnvelope XML
          3. FulfillmentEnvelope XML
        3. Discussion
        4. See Also
      10. 17.10. Putting Together an XML Document
        1. Problem
        2. Solution
          1. BillingEnvelope XML
          2. ShippingEnvelope XML
          3. FulfillmentEnvelope XML
        3. Discussion
        4. See Also
    19. Index
    20. Colophon