Cover image for C# 3.0 Cookbook, 3rd Edition

Book description

Completely updated for C# 3.0 and the .NET 3.5 platform, the new edition of this bestseller offers more than 250 code recipes to common and not-so-common problems that C# programmers face every day. Every recipe in the book has been reconsidered with more than a third of them rewritten to take advantage of new C# 3.0 features. If you prefer solutions you can use today to general C# language instruction, and quick answers to theory, this is your book. C# 3.0 Cookbook offers a new chapter on LINQ (language integrated query), plus two expanded chapters for recipes for extension methods, lambda functions, object initializers, new synchronization primitives and more. The new edition is also complemented by a public wiki, which not only includes all of the C# 2.0 recipes from the previous edition unchanged by the release of C# 3.0, but invites you to suggest better ways to solve those tasks. Here are some of topics covered:

  • LINQ

  • Numeric data types and Enumerations

  • Strings and characters

  • Classes and structures

  • Generics

  • Collections

  • Exception handling

  • Delegates, events, and lambda expressions

  • Filesystem interactions

  • Web site access

  • XML usage (including LINQ to XML, XPath and XSLT)

  • Networking

  • Threading

  • Data Structures & Algorithms

Each recipe in the book includes tested code that you can download from oreilly.com and reuse in your own applications, and each one includes a detailed discussion of how and why the underling technology works. You don't have to be an experienced C# or .NET developer to use C# 3.0 Cookbook. You just have to be someone who wants to solve a problem now, without having to learn all the related theory first.

Table of Contents

  1. C# 3.0 Cookbook, 3rd Edition
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Preface
    1. 00.1. Who This Book Is For
    2. 00.2. What You Need to Use This Book
    3. 00.3. Platform Notes
    4. 00.4. How This Book Is Organized
    5. 00.5. What Was Left Out
    6. 00.6. Conventions Used in This Book
    7. 00.7. About the Code
    8. 00.8. Using Code Examples
    9. 00.9. Comments and Questions
    10. 00.10. Safari® Books Online
    11. 00.11. Acknowledgments
      1. From Jay Hilyard
      2. From Steve Teilhet
  5. 1. Language Integrated Query (LINQ)
    1. 1.0. Introduction
    2. 1.1. Query a Message Queue
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 1.2. Using Set Semantics with Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 1.3. Reuse Parameterized Queries with LINQ to SQL
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 1.4. Sort Results in a Culture-Sensitive Manner
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 1.5. Adding Functional Extensions for Use with LINQ
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 1.6. Query and Join Across Data Repositories
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 1.7. Querying Configuration Files with LINQ
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 1.8. Creating XML Straight from a Database
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 1.9. Being Selective About Your Query Results
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 1.10. Using LINQ with Collections That Don't Support IEnumerable<T>
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  6. 2. Strings and Characters
    1. 2.0. Introduction
    2. 2.1. Determining the Kind of Character a Char Contains
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 2.2. Controlling Case Sensitivity When Comparing Two Characters
      1. Problem
      2. Solution
      3. Discussion
    4. 2.3. Finding the Location of All Occurrences of a String Within Another String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 2.4. Controlling Case Sensitivity When Comparing Two Strings
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 2.5. Comparing a String to the Beginning or End of a Second String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 2.6. Inserting Text into a String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 2.7. Removing or Replacing Characters Within a String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 2.8. Encoding Binary Data As Base64
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 2.9. Decoding a Base64-Encoded Binary
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 2.10. Converting a String Returned As a Byte[] Back into a String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 2.11. Passing a String to a Method That Accepts Only a Byte[]
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 2.12. Converting Strings to Other Types
      1. Problem
      2. Solution
      3. Discussion
    14. 2.13. Creating a Delimited String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 2.14. Extracting Items from a Delimited String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 2.15. Iterating over Each Character in a String
      1. Problem
      2. Solution
      3. Discussion
    17. 2.16. Pruning Characters from the Head and/or Tail of a String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 2.17. Testing a String for Null or Empty
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. 2.18. Appending a Line
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  7. 3. Classes and Structures
    1. 3.0. Introduction
    2. 3.1. Creating Union-Type Structures
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 3.2. Making a Type Sortable
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 3.3. Making a Type Searchable
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 3.4. Indirectly Overloading the +=, -=, /=, and *= Operators
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 3.5. Indirectly Overloading the &&, ||, and ?: Operators
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 3.6. Making Error-Free Expressions
      1. Problem
      2. Solution
      3. Discussion
    8. 3.7. Reducing Your Boolean Logic
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 3.8. Converting Between Simple Types in a Programming Language-Agnostic Manner
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 3.9. Determining When to Use the cast Operator, the as Operator, or the is Operator
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 3.10. Casting with the as Operator
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 3.11. Determining a Variable's Type with the is Operator
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 3.12. Returning Multiple Items from a Method
      1. Problem
      2. Solution
      3. Discussion
    14. 3.13. Parsing Command-Line Parameters
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 3.14. Initializing a Constant Field at Runtime
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 3.15. Building Cloneable Classes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. 3.16. Assuring an Object's Disposal
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 3.17. Disposing of Unmanaged Resources
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    19. 3.18. Determining Where Boxing and Unboxing Occur
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  8. 4. Generics
    1. 4.0. Introduction
    2. 4.1. Deciding When and Where to Use Generics
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 4.2. Understanding Generic Types
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 4.3. Replacing the ArrayList with Its Generic Counterpart
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 4.4. Replacing the Stack and Queue with Their Generic Counterparts
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 4.5. Using a Linked List
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 4.6. Creating a Value Type That Can Be Initialized to Null
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 4.7. Reversing the Contents of a Sorted List
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 4.8. Making Read-Only Collections the Generic Way
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 4.9. Replacing the Hashtable with Its Generic Counterpart
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 4.10. Using foreach with Generic Dictionary Types
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 4.11. Constraining Type Arguments
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 4.12. Initializing Generic Variables to Their Default Values
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  9. 5. Collections
    1. 5.0. Introduction
    2. 5.1. Swapping Two Elements in an Array
      1. Problem
      2. Solution
      3. Discussion
    3. 5.2. Reversing an Array Quickly
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 5.3. Writing a More Flexible StackTrace Class
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 5.4. Determining the Number of Times an Item Appears in a List<T>
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 5.5. Retrieving All Instances of a Specific Item in a List<T>
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 5.6. Inserting and Removing Items from an Array
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 5.7. Keeping Your List<T> Sorted
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 5.8. Sorting a Dictionary's Keys and/or Values
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 5.9. Creating a Dictionary with Max and Min Value Boundaries
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 5.10. Storing Snapshots of Lists in an Array
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 5.11. Persisting a Collection Between Application Sessions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 5.12. Testing Every Element in an Array or List<T>
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 5.13. Performing an Action on Each Element in an Array or List<T>
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 5.14. Creating a Read-Only Array or List<T>
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  10. 6. Iterators, Partial Types, and Partial Methods
    1. 6.0. Introduction
    2. 6.1. Creating an lterator on a Generic Type
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 6.2. Creating an Iterator on a Nongeneric Type
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 6.3. Creating Custom Enumerators
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 6.4. Implementing Iterator Logic
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 6.5. Forcing an Iterator to Stop Iterating
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 6.6. Dealing with Finally Blocks and Iterators
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 6.7. Implementing Nested foreach Functionality in a Class
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 6.8. Organizing Your Interface Implementations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 6.9. Generating Code That Is No Longer in Your Main Code Paths
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 6.10. Adding Hooks to Generated Entities
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  11. 7. Exception Handling
    1. 7.0. Introduction
    2. 7.1. Knowing When to Catch and Rethrow Exceptions
      1. Problem
      2. Solution
      3. Discussion
    3. 7.2. Assuring Exceptions Are Not Lost When Using Finally Blocks
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 7.3. Handling Exceptions Thrown from Methods Invoked via Reflection
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 7.4. Preventing Unhandled Exceptions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 7.5. Getting Exception Information
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 7.6. Getting to the Root of a Problem Quickly
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 7.7. Creating a New Exception Type
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 7.8. Obtaining a Stack Trace
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 7.9. Breaking on a First-Chance Exception
      1. Problem
      2. Solution
      3. See Also
    11. 7.10. Handling Exceptions Thrown from an Asynchronous Delegate
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 7.11. Giving Exceptions the Extra Info They Need with Exception.Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 7.12. Dealing with Unhandled Exceptions in WinForms Applications
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 7.13. Dealing with Unhandled Exceptions in Windows Presentation Foundation (WPF) Applications
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 7.14. Analyzing Exceptions for Common Errors
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  12. 8. Diagnostics
    1. 8.0. Introduction
    2. 8.1. Providing Fine-Grained Control over Debugging/ Tracing Output
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 8.2. Determining Whether a Process Has Stopped Responding
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 8.3. Using Event Logs in Your Application
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 8.4. Searching Event Log Entries
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 8.5. Watching the Event Log for a Specific Entry
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 8.6. Implementing a Simple Performance Counter
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 8.7. Enabling and Disabling Complex Tracing Code
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 8.8. Capturing Standard Output for a Process
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 8.9. Creating Custom Debugging Displays for Your Classes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  13. 9. Delegates, Events, and Lambda Expressions
    1. 9.0. Introduction
    2. 9.1. Controlling When and If a Delegate Fires Within a Multicast Delegate
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 9.2. Obtaining Return Values from Each Delegate in a Multicast Delegate
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 9.3. Handling Exceptions Individually for Each Delegate in a Multicast Delegate
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 9.4. Converting Delegate Invocation from Synchronous to Asynchronous
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 9.5. An Advanced Interface Search Mechanism
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 9.6. Observing Additions and Modifications to Dictionaries
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 9.7. Using Lambda Expressions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 9.8. Set Up Event Handlers Without the Mess
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 9.9. Using Different Parameter Modifiers in Lambda Expressions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 9.10. Using Closures in C#
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 9.11. Performing Multiple Operations on a List Using Functors
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  14. 10. Regular Expressions
    1. 10.0. Introduction
    2. 10.1. Enumerating Matches
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 10.2. Extracting Groups from a MatchCollection
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 10.3. Verifying the Syntax of a Regular Expression
      1. Problem
      2. Solution
      3. Discussion
    5. 10.4. Quickly Finding Only the Last Match in a String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 10.5. Augmenting the Basic String Replacement Function
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 10.6. Implementing a Better Tokenizer
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 10.7. Counting Lines of Text
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 10.8. Returning the Entire Line in Which a Match Is Found
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 10.9. Finding a Particular Occurrence of a Match
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 10.10. Using Common Patterns
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  15. 11. Data Structures and Algorithms
    1. 11.0. Introduction
    2. 11.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
    3. 11.2. Creating a Priority Queue
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 11.3. Creating a One-to-Many Map (MultiMap)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 11.4. Creating a Binary Search Tree
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 11.5. Creating an n-ary Tree
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 11.6. Using a HashSet Object
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  16. 12. Filesystem I/O
    1. 12.0. Introduction
    2. 12.1. Manipulating File Attributes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 12.2. Renaming a File
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 12.3. Outputting a Platform-Independent EOL Character
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 12.4. Manipulating Directory Attributes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 12.5. Renaming a Directory
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 12.6. Searching for Directories or Files Using Wildcards
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 12.7. Obtaining the Directory Tree
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 12.8. Parsing a Path
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 12.9. Parsing Paths in Environment Variables
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 12.10. Launching and Interacting with Console Utilities
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 12.11. Locking Subsections of a File
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 12.12. Waiting for an Action to Occur in the Filesystem
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 12.13. Comparing Version Information of Two Executable Modules
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 12.14. Querying Information for All Drives on a System
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 12.15. Compressing and Decompressing Your Files
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  17. 13. Reflection
    1. 13.0. Introduction
    2. 13.1. Listing Referenced Assemblies
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 13.2. Listing Exported Types
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 13.3. Finding Overridden Methods
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 13.4. Finding Members in an Assembly
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 13.5. Determining and Obtaining Nested Types Within an Assembly
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 13.6. Displaying the Inheritance Hierarchy for a Type
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 13.7. Finding the Subclasses of a Type
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 13.8. Finding All Serializable Types Within an Assembly
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 13.9. Dynamically Invoking Members
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 13.10. Determining If a Type or Method Is Generic
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 13.11. Accessing Local Variable Information
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 13.12. Creating a Generic Type
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  18. 14. Web
    1. 14.0. Introduction
    2. 14.1. Converting an IP Address to a Hostname
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 14.2. Converting a Hostname to an IP Address
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 14.3. Parsing a URI
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 14.4. Handling Web Server Errors
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 14.5. Communicating with a Web Server
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 14.6. Going Through a Proxy
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 14.7. Obtaining the HTML from a URL
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 14.8. Using the Web Browser Control
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 14.9. Tying Database Tables to the Cache
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 14.10. Prebuilding an ASP.NET Web SiteProgrammatically
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 14.11. Escaping and Unescaping Data for the Web
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 14.12. Using the UriBuilder Class
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 14.13. Inspect and Change Your Web Application Configuration
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 14.14. Using Cached Results When Working with HTTP for Faster Performance
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 14.15. Checking Out a Web Server's Custom Error Pages
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  19. 15. xml
    1. 15.0. Introduction
    2. 15.1. Reading and Accessing XML Data in Document Order
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 15.2. Reading XML on the Web
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 15.3. Querying the Contents of an XML Document
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 15.4. Validating XML
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 15.5. Creating an XML Document Programmatically
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 15.6. Detecting Changes to an XML Document
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 15.7. Handling Invalid Characters in an XML String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 15.8. Transforming XML
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 15.9. Tearing Apart an XML Document
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 15.10. Putting Together an XML Document
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 15.11. Validating Modified XML Documents Without Reloading
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 15.12. Extending Transformations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 15.13. Getting Your Schemas in Bulk from Existing XML Files
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 15.14. Passing Parameters to Transformations
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  20. 16. Networking
    1. 16.0. Introduction
    2. 16.1. Writing a TCP Server
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 16.2. Writing a TCP Client
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 16.3. Simulating Form Execution
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 16.4. Transferring Data via HTTP
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 16.5. Using Named Pipes to Communicate
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 16.6. Pinging Programmatically
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 16.7. Send SMTP Mail Using the SMTP Service
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 16.8. Use Sockets to Scan the Ports on a Machine
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 16.9. Use the Current Internet Connection Settings
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 16.10. Transferring Files Using FTP
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  21. 17. Security
    1. 17.0. Introduction
    2. 17.1. Controlling Access to Types in a Local Assembly
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 17.2. Encrypting/Decrypting a String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 17.3. Encrypting and Decrypting a File
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 17.4. Cleaning Up Cryptography Information
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 17.5. Verifying That a String Remains Uncorrupted Following Transmission
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 17.6. Storing Data Securely
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 17.7. Making a Security Assert Safe
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 17.8. Verifying That an Assembly Has Been Granted Specific Permissions
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 17.9. Minimizing the Attack Surface of an Assembly
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 17.10. Obtaining Security/Audit Information
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 17.11. Granting/Revoking Access to a File or Registry Key
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 17.12. Protecting String Data with Secure Strings
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 17.13. Securing Stream Data
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    15. 17.14. Encrypting web.config Information
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    16. 17.15. Obtaining the Full Reason a SecurityException Was Thrown
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    17. 17.16. Achieving Secure Unicode Encoding
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    18. 17.17. Obtaining a Safer File Handle
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  22. 18. Threading and Synchronization
    1. 18.0. Introduction
    2. 18.1. Creating Per-Thread Static Fields
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 18.2. Providing Thread-Safe Access to Class Members
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 18.3. Preventing Silent Thread Termination
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 18.4. Being Notified of the Completion of an Asynchronous Delegate
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 18.5. Storing Thread-Specific Data Privately
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 18.6. Granting Multiple Access to Resources with a Semaphore
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 18.7. Synchronizing Multiple Processes with the Mutex
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 18.8. Using Events to Make Threads Cooperate
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 18.9. Get the Naming Rights for Your Events
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 18.10. Performing Atomic Operations Among Threads
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 18.11. Optimizing Read-Mostly Access
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  23. 19. Toolbox
    1. 19.0. Introduction
    2. 19.1. Dealing with Operating System Shutdown, Power Management, or User Session Changes
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    3. 19.2. Controlling a Service
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    4. 19.3. List What Processes an Assembly Is Loaded In
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 19.4. Using Message Queues on a Local Workstation
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 19.5. Finding the Path to the Current Framework Version
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 19.6. Determining the Versions of an Assembly That Are Registered in the Global Assembly Cache (GAC)
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 19.7. Capturing Output from the Standard Output Stream
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    9. 19.8. Running Code in Its Own AppDomain
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 19.9. Determining the Operating System and Service Pack Version of the Current Operating System
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  24. 20. Numbers and Enumerations
    1. 20.0. Introduction
    2. 20.1. Converting Between Degrees and Radians
      1. Problem
      2. Solution
      3. Discussion
    3. 20.2. Using the Bitwise Complement Operator with Various Data Types
      1. Problem
      2. Solution
      3. Discussion
    4. 20.3. Converting a Number in Another Base to Base10
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    5. 20.4. Determining Whether a String Is a Valid Number
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    6. 20.5. Rounding a Floating-Point Value
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    7. 20.6. Choosing a Rounding Algorithm
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    8. 20.7. Converting Between Temperature Scales
      1. Problem
      2. Solution
      3. Discussion
    9. 20.8. Safely Performing a Narrowing Numeric Cast
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    10. 20.9. Displaying an Enumeration Value as a String
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    11. 20.10. Converting Plain Text to an Equivalent Enumeration Value
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    12. 20.11. Testing for a Valid Enumeration Value
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    13. 20.12. Testing for a Valid Enumeration of Flags
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
    14. 20.13. Using Enumerated Members in a Bit Mask
      1. Problem
      2. Solution
      3. Discussion
    15. 20.14. Determining Whether One or More Enumeration Flags Are Set
      1. Problem
      2. Solution
      3. Discussion
    16. 20.15. Determining the Integral Part of a Decimal or Double
      1. Problem
      2. Solution
      3. Discussion
      4. See Also
  25. About the Authors
  26. Colophon
  27. Copyright