Books & Videos

Table of Contents

  1. Chapter 1 Numbers and Enumerations

    1. Introduction

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

    3. Converting Degrees to Radians

    4. Converting Radians to Degrees

    5. Using the Bitwise Complement Operator with Various Data Types

    6. Testing for an Even or Odd Value

    7. Obtaining the High Word or Low Word of a Number

    8. Converting a Number in Another Base to Base10

    9. Determining Whether a String Is a Valid Number

    10. Rounding a Floating-Point Value

    11. Choosing a Rounding Algorithm

    12. Converting Celsius to Fahrenheit

    13. Converting Fahrenheit to Celsius

    14. Safely Performing a Narrowing Numeric Cast

    15. Finding the Length of Any Three Sides of a Right Triangle

    16. Finding the Angles of a Right Triangle

    17. Displaying an Enumeration Value as a String

    18. Converting Plain Text to an Equivalent Enumeration Value

    19. Testing for a Valid Enumeration Value

    20. Testing for a Valid Enumeration of Flags

    21. Using Enumerated Members in a Bit Mask

    22. Determining if One or More Enumeration Flags Are Set

    23. Determining the Integral Part of a Decimal or Double

  2. Chapter 2 Strings and Characters

    1. Introduction

    2. Determining the Kind of Character a char Contains

    3. Determining Whether a Character Is Within a Specified Range

    4. Controlling Case Sensitivity When Comparing Two Characters

    5. Finding All Occurrences of a Character Within a String

    6. Finding the Location of All Occurrences of a String Within Another String

    7. Implementing a Poor Man's Tokenizer to Deconstruct a String

    8. Controlling Case Sensitivity When Comparing Two Strings

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

    10. Inserting Text into a String

    11. Removing or Replacing Characters Within a String

    12. Encoding Binary Data as Base64

    13. Decoding a Base64-Encoded Binary

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

    15. Passing a String to a Method That Accepts only a Byte[ ]

    16. Converting Strings to Other Types

    17. Formatting Data in Strings

    18. Creating a Delimited String

    19. Extracting Items from a Delimited String

    20. Setting the Maximum Number of Characters a StringBuilder Can Contain

    21. Iterating over Each Character in a String

    22. Improving String Comparison Performance

    23. Improving StringBuilder Performance

    24. Pruning Characters from the Head and/or Tail of a String

    25. Testing a String for Null or Empty

    26. Appending a Line

    27. Encoding Chunks of Data

  3. Chapter 3 Classes and Structures

    1. Introduction

    2. Creating Union-Type Structures

    3. Allowing a Type to Represent Itself as a String

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

    5. Implementing Polymorphism with Abstract Base Classes

    6. Making a Type Sortable

    7. Making a Type Searchable

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

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

    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 When to Use the Cast Operator, the as Operator, or the is Operator

    15. Casting with the as Operator

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

    17. Implementing Polymorphism with Interfaces

    18. Calling the Same Method on Multiple Object Types

    19. Adding a Notification Callback Using an Interface

    20. Using Multiple Entry Points to Version 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. Building Cloneable Classes

    28. Assuring an Object's Disposal

    29. Releasing a COM Object Through Managed Code

    30. Creating an Object Cache

    31. Rolling Back Object Changes

    32. Disposing of Unmanaged Resources

    33. Determining Where Boxing and Unboxing Occur

  4. Chapter 4 Generics

    1. Introduction

    2. Deciding When and Where to Use Generics

    3. Understanding Generic Types

    4. Getting the Type of a Generic Type

    5. Replacing the ArrayList with Its Generic Counterpart

    6. Replacing the Stack and Queue with Their Generic Counterparts

    7. Implementing a Linked List

    8. Creating a Value Type That Can Be Initialized to Null

    9. Reversing the Contents of a Sorted List

    10. Making Read-Only Collections the Generic Way

    11. Replacing the Hashtable with Its Generic Counterpart

    12. Using foreach with Generic Dictionary Types

    13. Constraining Type Arguments

    14. Initializing Generic Variables to Their Default Values

  5. Chapter 5 Collections

    1. Introduction

    2. Swapping Two Elements in an Array

    3. Reversing an Array Quickly

    4. Reversing a Two-Dimensional Array

    5. Reversing a Jagged Array

    6. Writing a More Flexible StackTrace Class

    7. Determining the Number of Times an Item Appears in a List<T>

    8. Retrieving All Instances of a Specific Item in a List<T>

    9. Inserting and Removing Items from an Array

    10. Keeping Your List<T> Sorted

    11. Sorting a Dictionary's Keys and/or Values

    12. Creating a Dictionary 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. Persisting a Collection Between Application Sessions

    16. Testing Every Element in an Array or List<T>

    17. Performing an Action on Each Element in an Array or List<T>

    18. Creating a Read-Only Array or List<T>

  6. Chapter 6 Iterators and Partial Types

    1. Introduction

    2. Implementing Nested foreach Functionality in a Class

    3. Creating Custom Enumerators

    4. Creating an Iterator on a Generic Type

    5. Creating an Iterator on a Non-generic Type

    6. Creating Iterators That Accept Parameters

    7. Adding Multiple Iterators on a Single Type

    8. Implementing Iterators as Overloaded Operators

    9. Forcing an Iterator to Stop Iterating

    10. Dealing with Finally Blocks and Iterators

    11. Organizing Your Interface Implementations

    12. Generating Code That Is No Longer in Your Main Code Paths

  7. Chapter 7 Exception Handling

    1. Introduction

    2. Verifying Critical Parameters

    3. Knowing When to Catch and Rethrow Exceptions

    4. Identifying Exceptions and Their Usage

    5. Handling Derived Exceptions Individually

    6. Assuring Exceptions Are Not Lost When Using Finally Blocks

    7. Handling Exceptions Thrown from Methods Invoked via Reflection

    8. Debugging Problems When Loading an Assembly

    9. Mapping Back and Forth Between Managed Exceptions and HRESULTs

    10. Handling User-Defined HRESULTs

    11. Preventing Unhandled Exceptions

    12. Getting Exception Information

    13. Getting to the Root of a Problem Quickly

    14. Creating a New Exception Type

    15. Obtaining a Stack Trace

    16. Breaking on a First-Chance Exception

    17. Preventing the Nefarious TypeInitializationException

    18. Handling Exceptions Thrown from an Asynchronous Delegate

    19. Giving Exceptions the Extra Info They Need with Exception.Data

    20. Looking at Exceptions in a New Way Using Visualizers

    21. Dealing with Unhandled Exceptions in WinForms Applications

  8. Chapter 8 Diagnostics

    1. Introduction

    2. Controlling Tracing Output in Production Code

    3. Providing Fine-Grained Control over Debugging/Tracing Output

    4. Creating Your Own Custom Switch Class

    5. Compiling Blocks of Code Conditionally

    6. Determining Whether a Process Has Stopped Responding

    7. Using 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. Enabling and Disabling Complex Tracing Code

    15. Capturing Standard Output for a Process

    16. Creating Custom Debugging Displays for Your Classes

    17. Determining Current appdomain Settings Information

    18. Boosting the Priority of a Process Programmatically

    19. Looking at Your Runtime Environment and Seeing What You Can Do About It

  9. Chapter 9 Delegates, Events, and Anonymous Methods

    1. Introduction

    2. Controlling When and If a Delegate Fires Within a Multicast Delegate

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

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

    5. Converting Delegate Invocation from Synchronous to Asynchronous

    6. Wrapping Sealed Classes to Add Events

    7. Passing Specialized Parameters to and from an Event

    8. An Advanced Interface Search Mechanism

    9. An Advanced Member Search Mechanism

    10. Observing Additions and Modifications to a Hashtable

    11. Using the Windows Keyboard Hook

    12. Tracking and Responding to the Mouse

    13. Using Anonymous Methods

    14. Set up Event Handlers Without the Mess

    15. Using Different Parameter Modifiers in Anonymous Methods

    16. Using Closures in C#

    17. Performing Multiple Operations on a List Using Functors

  10. Chapter 10 Regular Expressions

    1. Introduction

    2. Enumerating Matches

    3. Extracting Groups from a MatchCollection

    4. Verifying the Syntax of a Regular Expression

    5. Quickly Finding Only the Last Match in a String

    6. Replacing Characters or Words in a String

    7. Augmenting the Basic String Replacement Function

    8. Implementing a Better Tokenizer

    9. Compiling Regular Expressions

    10. Counting Lines of Text

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

    12. Finding a Particular Occurrence of a Match

    13. Using Common Patterns

    14. Documenting Your Regular Expressions

    15. Using Built-in Regular Expressions to Parse ASP. NET Pages

  11. Chapter 11 Data Structures and Algorithms

    1. Introduction

    2. Creating a Hash Code for a Data Type

    3. Creating a Priority Queue

    4. Creating a Double Queue

    5. Determining Where Characters or Strings Do Not Balance

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

    7. Creating a Binary Tree

    8. Creating an n-ary Tree

    9. Creating a Set Object

  12. Chapter 12 Filesystem I/O

    1. Introduction

    2. Creating, Copying, Moving, or Deleting a File

    3. Manipulating File Attributes

    4. Renaming a File

    5. Determining Whether a File Exists

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

    7. Accessing Part of a File Randomly

    8. Outputting a Platform-Independent EOL Character

    9. Creating, Writing to, and Reading from a File

    10. Determining Whether a Directory Exists

    11. Creating, Copying, Moving, or Deleting a Directory

    12. Manipulating Directory Attributes

    13. Renaming a Directory

    14. Searching for Directories or Files Using Wildcards

    15. Obtaining the Directory Tree

    16. Parsing a Path

    17. Parsing Paths in Environment Variables

    18. Verifying a Path

    19. Using a Temporary File in Your Application

    20. Opening a File Stream with Just a File Handle

    21. Writing to Multiple Output Files at One Time

    22. Launching and Interacting with Console Utilities

    23. Locking Subsections of a File

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

    25. Waiting for an Action to Occur in the Filesystem

    26. Comparing Version Information of Two Executable Modules

    27. Querying Information for All Drives on a System

    28. Encrypting/Decrypting an Existing File

    29. Compressing and Decompressing Your Files

  13. Chapter 13 Reflection

    1. Introduction

    2. Listing Referenced Assemblies

    3. Listing Exported Types

    4. Finding Overridden Methods

    5. Finding Members in an Assembly

    6. Finding Members Within an Interface

    7. Determining and Obtaining Nested Types Within an Assembly

    8. Displaying the Inheritance Hierarchy for a Type

    9. Finding the Subclasses of a Type

    10. Finding All Serializable Types Within an Assembly

    11. Filtering Output When Obtaining Members

    12. Dynamically Invoking Members

    13. Providing Guidance to Obfuscators

    14. Determining if a Type or Method Is Generic

    15. Reading Manifest Resources Programmatically

    16. Accessing Local Variable Information

    17. Creating a Generic Type

  14. Chapter 14 Web

    1. Introduction

    2. Converting an IP Address to a Hostname

    3. Converting a Hostname to an IP Address

    4. Parsing a URI

    5. Forming and Validating an Absolute Uri

    6. Handling Web Server Errors

    7. Communicating with a Web Server

    8. Going Through a Proxy

    9. Obtaining the HTML from a URL

    10. Using the New Web Browser Control

    11. Tying Database Tables to the Cache

    12. Caching Data with Multiple Dependencies

    13. Prebuilding an ASP.NET Web Site Programmatically

    14. Escaping and Unescaping Data for the Web

    15. Using the UriBuilder Class

    16. Inspect and Change Your Web Application Configuration

    17. Working with HTML

    18. Using Cached Results When Working with HTTP for Faster Performance

    19. Checking out a Web Server's Custom Error Pages

    20. Determining the Application Mappings for ASP.NET Set Up on IIS

  15. Chapter 15 XML

    1. Introduction

    2. Reading and Accessing XML Data in Document Order

    3. Reading XML on the Web

    4. Querying the Contents of an XML Document

    5. Validating XML

    6. Creating an XML Document Programmatically

    7. Detecting Changes to an XML Document

    8. Handling Invalid Characters in an XML String

    9. Transforming XML

    10. Tearing Apart an XML Document

    11. Putting Together an XML Document

    12. Validating Modified XML Documents Without Reloading

    13. Extending XSLT Transformations

    14. Getting Your Schema in Bulk from Existing XML Files

    15. Passing Parameters to XSLT Transformations

  16. Chapter 16 Networking

    1. Introduction

    2. Writing a TCP Server

    3. Writing a TCP Client

    4. Simulating Form Execution

    5. Downloading Data from a Server

    6. Using Named Pipes to Communicate

    7. Pinging Programmatically

    8. Send SMTP Mail Using the SMTP Service

    9. Check out Your Network Connectivity

    10. Use Sockets to Scan the Ports on a Machine

    11. Use the Current Internet Connection Settings

    12. Download a File Using FTP

  17. Chapter 17 Security

    1. Introduction

    2. Controlling Access to Types in a Local Assembly

    3. Encrypting/Decrypting a String

    4. Encrypting and Decrypting a File

    5. Cleaning up Cryptography Information

    6. Verifying that a String Remains Uncorrupted Following Transmission

    7. Wrapping a String Hash for Ease of Use

    8. A Better Random Number Generator

    9. Storing Data Securely

    10. Making a Security Assert Safe

    11. Preventing Malicious Modifications to an Assembly

    12. Verifying That an Assembly Has Been Granted Specific Permissions

    13. Minimizing the Attack Surface of an Assembly

    14. Obtaining Security/Audit Information

    15. Granting/Revoking Access to a File or Registry Key

    16. Protecting String Data with Secure Strings

    17. Securing Stream Data

    18. Encrypting web.config Information

    19. Obtaining the Full Reason a SecurityException Was Thrown

    20. Achieving Secure Unicode Encoding

    21. Obtaining a Safer File Handle

  18. Chapter 18 Threading and Synchronization

    1. Introduction

    2. Creating Per-Thread Static Fields

    3. Providing Thread-Safe Access to Class Members

    4. Preventing Silent Thread Termination

    5. Polling an Asynchronous Delegate

    6. Timing out an Asynchronous Delegate

    7. Being Notified of the Completion of an Asynchronous Delegate

    8. Determining Whether a Request for a Pooled Thread Will Be Queued

    9. Configuring a Timer

    10. Storing Thread-Specific Data Privately

    11. Granting Multiple Access to Resources with a Semaphore

    12. Synchronizing Multiple Processes with the Mutex

    13. Using Events to Make Threads Cooperate

    14. Get the Naming Rights for Your Events

    15. Performing Atomic Operations Among Threads

  19. Chapter 19 Unsafe Code

    1. Introduction

    2. Controlling Changes to Pointers Passed to Methods

    3. Comparing Pointers

    4. Navigating Arrays

    5. Manipulating a Pointer to a Fixed Array

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

    7. Creating and Using an Array of Pointers

    8. Switching Unknown Pointer Types

    9. Converting a String to a char*

    10. Declaring a Fixed-Size Structure with an Embedded Array

  20. Chapter 20 Toolbox

    1. Introduction

    2. Dealing with Operating System Shutdown, Power Management, or User Session Changes

    3. Controlling a Service

    4. List What Processes an Assembly Is Loaded In

    5. Using Message Queues on a Local Workstation

    6. Finding the Path to the Current Framework Version

    7. Determining the Versions of an Assembly That Are Registered in the Global Assembly Cache (GAC)

    8. Getting the Windows Directory

    9. Capturing Output from the Standard Output Stream

    10. Running Code in Its Own appdomain

    11. Determining the Operating System and Service Pack Version of the Current Operating System

  1. Colophon