Books & Videos

Table of Contents

  1. Chapter 1 Numbers

    1. Determining Approximate Equality Between a Fraction and Floating-Point Value

    2. Converting Degrees to Radians

    3. Converting Radians to Degrees

    4. Using the Bitwise Complement Operator with Various Data Types

    5. Test for an Even or Odd Value

    6. Obtaining the Most- or Least-Significant Bits of a Number

    7. Converting a Number in Another Base to Base10

    8. Determining Whether a String Is a Valid Number

    9. Rounding a Floating-Point Value

    10. Different Rounding Algorithms

    11. Converting Celsius to Fahrenheit

    12. Converting Fahrenheit to Celsius

    13. Safely Performing a Narrowing Numeric Cast

    14. Finding the Length of Any Three Sidesof a Right Triangle

    15. Finding the Angles of a Right Triangle

  2. Chapter 2 Strings and Characters

    1. Determining the Kind of Character

    2. Determining Whether a Character Is Within a Specified Range

    3. Controlling Case Sensitivity when Comparing Two Characters

    4. Finding All Occurrences of a Character Within a String

    5. Finding the Location of All Occurrencesof a String Within Another String

    6. The Poor Man’s Tokenizer

    7. Controlling Case Sensitivity when Comparing Two Strings

    8. Comparing a String to the Beginning or End of a Second String

    9. Inserting Text into a String

    10. Removing or Replacing Characters Within a String

    11. Encoding Binary Data as Base64

    12. Decoding a Base64-Encoded Binary

    13. Converting a String Returned as a Byte[ ] Back into a String

    14. Passing a String to a Method that Accepts Only a Byte[ ]

    15. Converting Strings to Their Equivalent Value Type

    16. Formatting Data in Strings

    17. Creating a Delimited String

    18. Extracting Items from a Delimited String

    19. Setting the Maximum Number of Characters a String Can Contain

    20. Iterating Over Each Character in a String

    21. Improving String Comparison Performance

    22. Improving StringBuilder Performance

    23. Pruning Characters from the Headand/or Tail of a String

  3. Chapter 3 Classes and Structures

    1. Creating Union-Type Structures

    2. Allowing a Type to Represent Itself as a String

    3. Converting a String Representation of an Object into an Actual Object

    4. Polymorphism via Concrete or Abstract Base Classes

    5. Making a Type Sortable

    6. Making a Type Searchable

    7. Indirectly Overloading the +=, -=, /=, and *= Operators

    8. Indirectly Overloading the &&, ||, and ?: Operators

    9. Improving the Performance of a Structure’s Equals Method

    10. Turning Bits On or Off

    11. Making Error-Free Expressions

    12. Minimizing (Reducing) Your Boolean Logic

    13. Converting Between Simple Types in a Language Agnostic Manner

    14. Determining Whether to Use theCast Operator, the as Operator, or theis Operator

    15. Casting with the as Operator

    16. Determining a Variable’s Type with the is Operator

    17. Polymorphism via Interfaces

    18. Calling the Same Method on Multiple Object Types

    19. Adding a Notification Callback Using an Interface

    20. Using Multiple Entry Points toVersion an Application

    21. Preventing the Creation of an Only Partially Initialized Object

    22. Returning Multiple Items from a Method

    23. Parsing Command-Line Parameters

    24. Retrofitting a Class to Interoperate with COM

    25. Initializing a Constant Field at Runtime

    26. Writing Code that Is Compatible with the Widest Range of Managed Languages

    27. Implementing Nested foreach Functionality in a Class

    28. Building Cloneable Classes

    29. Assuring an Object’s Disposal

    30. Releasing a COM Object ThroughManaged Code

    31. Creating an Object Cache

    32. The Single Instance Object

    33. Choosing a Serializer

    34. Creating Custom Enumerators

    35. Rolling Back Object Changes

    36. Disposing of Unmanaged Resources

    37. Determining Where Boxing and Unboxing Occur

  4. Chapter 4 Enumerations

    1. Displaying an Enumeration Value as a String

    2. Converting Plain Text to an Equivalent Enumeration Value

    3. Testing for a Valid Enumeration Value

    4. Testing for a Valid Enumeration of Flags

    5. Using Enumerated Members in a Bitmask

    6. Determining Whether One or More Enumeration Flags Are Set

  5. Chapter 5 Exception Handling

    1. Verifying Critical Parameters

    2. Indicating Where Exceptions Originate

    3. Choosing when to Throw a Particular Exception

    4. Handling Derived Exceptions Individually

    5. Assuring Exceptions are Not Lost when Using Finally Blocks

    6. Handling Exceptions Thrown from Methods Invoked via Reflection

    7. Debugging Problems whenLoading an Assembly

    8. HRESULT-Exception Mapping

    9. Handling User-Defined HRESULTs

    10. Preventing Unhandled Exceptions

    11. Displaying Exception Information

    12. Getting to the Root of a Problem Quickly

    13. Creating a New Exception Type

    14. Obtaining a Stack Trace

    15. Breaking on a First Chance Exception

    16. Preventing the Nefarious TypeInitializationException

    17. Handling Exceptions Thrown from an Asynchronous Delegate

  6. Chapter 6 Diagnostics

    1. Controlling Tracing Output inProduction Code

    2. Providing Fine-Grained Control Over Debugging/Tracing Output

    3. Creating Your Own Custom Switch Class

    4. A Custom Trace Class that Outputs Information in an XML Format

    5. Conditionally Compiling Blocks of Code

    6. Determining Whether a Process Has Stopped Responding

    7. Using One or More Event Logs in Your Application

    8. Changing the Maximum Size of a Custom Event Log

    9. Searching Event Log Entries

    10. Watching the Event Log for a Specific Entry

    11. Finding All Sources Belonging to a Specific Event Log

    12. Implementing a Simple Performance Counter

    13. Implementing Performance Counters that Require a Base Counter

    14. Enable/Disable Complex Tracing Code

  7. Chapter 7 Delegates and Events

    1. Controlling when and if a Delegate Fires Within a Multicast Delegate

    2. Obtaining Return Values from Each Delegate in a Multicast Delegate

    3. Handling Exceptions Individually for Each Delegate in a Multicast Delegate

    4. Converting a Synchronous Delegate to an Asynchronous Delegate

    5. Adding Events to a Sealed Class

    6. Passing Specialized Parameters to and from an Event

    7. An Advanced Interface Search Mechanism

    8. An Advanced Member Search Mechanism

    9. Observing Additions and Modifications to a Hashtable

    10. Using the Windows Keyboard Hook

    11. Using Windows Hooks to Manipulate the Mouse

  8. Chapter 8 Regular Expressions

    1. Enumerating Matches

    2. Extracting Groups from a MatchCollection

    3. Verifying the Syntax of a Regular Expression

    4. Quickly Finding Only the Last Match in a String

    5. Replacing Characters or Words in a String

    6. Augmenting the Basic String Replacement Function

    7. A Better Tokenizer

    8. Compiling Regular Expressions

    9. Counting Lines of Text

    10. Returning the Entire Line in Which a Match Is Found

    11. Finding a Particular Occurrence of a Match

    12. Using Common Patterns

    13. Documenting Your Regular Expressions

  9. Chapter 9 Collections

    1. Swapping Two Elements in an Array

    2. Quickly Reversing an Array

    3. Reversing a Two-Dimensional Array

    4. Reversing a Jagged Array

    5. A More Flexible StackTrace Class

    6. Determining the Number of Times an Item Appears in an ArrayList

    7. Retrieving All Instances of a Specific Itemin an ArrayList

    8. Inserting and Removing Items from an Array

    9. Keeping Your ArrayList Sorted

    10. Sorting a Hashtable’s Keys and/or Values

    11. Creating a Hashtable with Max and Min Size Boundaries

    12. Creating a Hashtable with Max and Min Value Boundaries

    13. Displaying an Array’s Data as a Delimited String

    14. Storing Snapshots of Lists in an Array

    15. Creating a Strongly Typed Collection

    16. Persisting a Collection Between Application Sessions

  10. Chapter 10 Data Structures and Algorithms

    1. Creating a Hash Code for a Data Type

    2. Creating a Priority Queue

    3. Creating a More Versatile Queue

    4. Determining Where Characters or Strings Do Not Balance

    5. Creating a One-to-Many Map (MultiMap)

    6. Creating a Binary Tree

    7. Creating an n-ary Tree

    8. Creating a Set Object

  11. Chapter 11 Filesystem I/O

    1. Creating, Copying, Moving, and Deleting a File

    2. Manipulating File Attributes

    3. Renaming a File

    4. Determining Whether a File Exists

    5. Choosing a Method of Opening a File or Stream for Reading and/or Writing

    6. Randomly Accessing Part of a File

    7. Outputting a Platform-Independent EOL Character

    8. Create, Write to, and Read from a File

    9. Determining Whether a Directory Exists

    10. Creating, Moving, and Deleting a Directory

    11. Manipulating Directory Attributes

    12. Renaming a Directory

    13. Searching for Directories or FilesUsing Wildcards

    14. Obtaining the Directory Tree

    15. Parsing a Path

    16. Parsing Paths in Environment Variables

    17. Verifying a Path

    18. Using a Temporary File in Your Application

    19. Opening a File Stream with just aFile Handle

    20. Write to Multiple Output Files at One Time

    21. Launching and Interacting withConsole Utilities

    22. Locking Subsections of a File

    23. Watching the Filesystem for Specific Changes to One or More Files or Directories

    24. Waiting for an Action to Occurin the Filesystem

    25. Comparing Version Information of Two Executable Modules

  12. Chapter 12 Reflection

    1. Listing Imported Assemblies

    2. Listing Exported Types

    3. Finding Overridden Methods

    4. Finding Members in an Assembly

    5. Finding Members Within an Interface

    6. Obtaining Types Nested Within a Type

    7. Displaying the Inheritance Hierarchy for a Type

    8. Finding the Subclasses of a Type

    9. Finding All Serializable Types Within an Assembly

    10. Controlling Additions to an ArrayList Through Attributes

    11. Filtering Output when Obtaining Members

    12. Dynamically Invoking Members

  13. Chapter 13 Networking

    1. Converting an IP Address to a Hostname

    2. Converting a Hostname to an IP Address

    3. Parsing a URI

    4. Forming an Absolute URI

    5. Handling Web Server Errors

    6. Communicating with a Web Server

    7. Going Through a Proxy

    8. Obtaining the HTML from a URL

    9. Writing a TCP Server

    10. Writing a TCP Client

    11. Simulating Form Execution

    12. Downloading Data from a Server

    13. Using Named Pipes to Communicate

  14. Chapter 14 Security

    1. Controlling Access to Types in aLocal Assembly

    2. Encrypting/Decrypting a String

    3. Encrypting and Decrypting a File

    4. Cleaning Up Cryptography Information

    5. Verifying that a String Is Uncorrupted During Transmission

    6. Wrapping a String Hash for Ease of Use

    7. A Better Random Number Generator

    8. Securely Storing Data

    9. Making a Security Assert Safe

    10. Preventing Malicious Modifications to an Assembly

    11. Verifying that an Assembly Has Been Granted Specific Permissions

    12. Minimizing the Attack Surface of an Assembly

  15. Chapter 15 Threading

    1. Creating Per-Thread Static Fields

    2. Providing Thread Safe Access to Class Members

    3. Preventing Silent Thread Termination

    4. Polling an Asynchronous Delegate

    5. Timing Out an Asynchronous Delegate

    6. Being Notified of the Completionof an Asynchronous Delegate

    7. Waiting for Worker Thread Completion

    8. Synchronizing the Reading and Writingof a Resource Efficiently

    9. Determining Whether a Requestfor a Pooled Thread Will Be Queued

    10. Waiting for All Threads in theThread Pool to Finish

    11. Configuring a Timer

    12. Storing Thread-Specific Data Privately

  16. Chapter 16 Unsafe Code

    1. Controlling Changes to Pointers Passedto Methods

    2. Comparing Pointers

    3. Navigating Arrays

    4. Manipulating a Pointer to a Fixed Array

    5. Returning a Pointer to a Particular Element in an Array

    6. Creating and Using an Array of Pointers

    7. Creating and Using an Array of Pointersto Unknown Types

    8. Switching Unknown Pointer Types

    9. Breaking Up Larger Numbers into Their Equivalent Byte Array Representation

    10. Converting Pointers to a Byte[ ], SByte[ ],or Char[ ] to a String

  17. Chapter 17 XML

    1. Reading and Accessing XML Datain Document Order

    2. Reading XML on the Web

    3. Querying the Contents of an XML Document

    4. Validating XML

    5. Creating an XML Document Programmatically

    6. Detecting Changes to an XML Document

    7. Handling Invalid Characters in anXML String

    8. Transforming XML to HTML

    9. Tearing Apart an XML Document

    10. Putting Together an XML Document

  1. Colophon