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. More than a third of the recipes have been rewritten to take advantage of new C# 3.0 features. If you prefer solutions to general C# language instruction and quick answers to theory, this is your book.
Full Description
Table of Contents
-
Chapter 1 Language Integrated Query (LINQ)
-
Introduction
-
Query a Message Queue
-
Using Set Semantics with Data
-
Reuse Parameterized Queries with LINQ to SQL
-
Sort Results in a Culture-Sensitive Manner
-
Adding Functional Extensions for Use with LINQ
-
Query and Join Across Data Repositories
-
Querying Configuration Files with LINQ
-
Creating XML Straight from a Database
-
Being Selective About Your Query Results
-
Using LINQ with Collections That Don't Support IEnumerable<T>
-
-
Chapter 2 Strings and Characters
-
Introduction
-
Determining the Kind of Character a Char Contains
-
Controlling Case Sensitivity When Comparing Two Characters
-
Finding the Location of All Occurrences of a String Within Another String
-
Controlling Case Sensitivity When Comparing Two Strings
-
Comparing a String to the Beginning or End of a Second String
-
Inserting Text into a String
-
Removing or Replacing Characters Within a String
-
Encoding Binary Data As Base64
-
Decoding a Base64-Encoded Binary
-
Converting a String Returned As a Byte[] Back into a String
-
Passing a String to a Method That Accepts Only a Byte[]
-
Converting Strings to Other Types
-
Creating a Delimited String
-
Extracting Items from a Delimited String
-
Iterating over Each Character in a String
-
Pruning Characters from the Head and/or Tail of a String
-
Testing a String for Null or Empty
-
Appending a Line
-
-
Chapter 3 Classes and Structures
-
Introduction
-
Creating Union-Type Structures
-
Making a Type Sortable
-
Making a Type Searchable
-
Indirectly Overloading the +=, -=, /=, and *= Operators
-
Indirectly Overloading the &&, ||, and ?: Operators
-
Making Error-Free Expressions
-
Reducing Your Boolean Logic
-
Converting Between Simple Types in a Programming Language-Agnostic Manner
-
Determining When to Use the cast Operator, the as Operator, or the is Operator
-
Casting with the as Operator
-
Determining a Variable's Type with the is Operator
-
Returning Multiple Items from a Method
-
Parsing Command-Line Parameters
-
Initializing a Constant Field at Runtime
-
Building Cloneable Classes
-
Assuring an Object's Disposal
-
Disposing of Unmanaged Resources
-
Determining Where Boxing and Unboxing Occur
-
-
Chapter 4 Generics
-
Introduction
-
Deciding When and Where to Use Generics
-
Understanding Generic Types
-
Replacing the ArrayList with Its Generic Counterpart
-
Replacing the Stack and Queue with Their Generic Counterparts
-
Using a Linked List
-
Creating a Value Type That Can Be Initialized to Null
-
Reversing the Contents of a Sorted List
-
Making Read-Only Collections the Generic Way
-
Replacing the Hashtable with Its Generic Counterpart
-
Using foreach with Generic Dictionary Types
-
Constraining Type Arguments
-
Initializing Generic Variables to Their Default Values
-
-
Chapter 5 Collections
-
Introduction
-
Swapping Two Elements in an Array
-
Reversing an Array Quickly
-
Writing a More Flexible StackTrace Class
-
Determining the Number of Times an Item Appears in a List<T>
-
Retrieving All Instances of a Specific Item in a List<T>
-
Inserting and Removing Items from an Array
-
Keeping Your List<T> Sorted
-
Sorting a Dictionary's Keys and/or Values
-
Creating a Dictionary with Max and Min Value Boundaries
-
Storing Snapshots of Lists in an Array
-
Persisting a Collection Between Application Sessions
-
Testing Every Element in an Array or List<T>
-
Performing an Action on Each Element in an Array or List<T>
-
Creating a Read-Only Array or List<T>
-
-
Chapter 6 Iterators, Partial Types, and Partial Methods
-
Introduction
-
Creating an lterator on a Generic Type
-
Creating an Iterator on a Nongeneric Type
-
Creating Custom Enumerators
-
Implementing Iterator Logic
-
Forcing an Iterator to Stop Iterating
-
Dealing with Finally Blocks and Iterators
-
Implementing Nested foreach Functionality in a Class
-
Organizing Your Interface Implementations
-
Generating Code That Is No Longer in Your Main Code Paths
-
Adding Hooks to Generated Entities
-
-
Chapter 7 Exception Handling
-
Introduction
-
Knowing When to Catch and Rethrow Exceptions
-
Assuring Exceptions Are Not Lost When Using Finally Blocks
-
Handling Exceptions Thrown from Methods Invoked via Reflection
-
Preventing Unhandled Exceptions
-
Getting Exception Information
-
Getting to the Root of a Problem Quickly
-
Creating a New Exception Type
-
Obtaining a Stack Trace
-
Breaking on a First-Chance Exception
-
Handling Exceptions Thrown from an Asynchronous Delegate
-
Giving Exceptions the Extra Info They Need with Exception.Data
-
Dealing with Unhandled Exceptions in WinForms Applications
-
Dealing with Unhandled Exceptions in Windows Presentation Foundation (WPF) Applications
-
Analyzing Exceptions for Common Errors
-
-
Chapter 8 Diagnostics
-
Introduction
-
Providing Fine-Grained Control over Debugging/ Tracing Output
-
Determining Whether a Process Has Stopped Responding
-
Using Event Logs in Your Application
-
Searching Event Log Entries
-
Watching the Event Log for a Specific Entry
-
Implementing a Simple Performance Counter
-
Enabling and Disabling Complex Tracing Code
-
Capturing Standard Output for a Process
-
Creating Custom Debugging Displays for Your Classes
-
-
Chapter 9 Delegates, Events, and Lambda Expressions
-
Introduction
-
Controlling When and If a Delegate Fires Within a Multicast Delegate
-
Obtaining Return Values from Each Delegate in a Multicast Delegate
-
Handling Exceptions Individually for Each Delegate in a Multicast Delegate
-
Converting Delegate Invocation from Synchronous to Asynchronous
-
An Advanced Interface Search Mechanism
-
Observing Additions and Modifications to Dictionaries
-
Using Lambda Expressions
-
Set Up Event Handlers Without the Mess
-
Using Different Parameter Modifiers in Lambda Expressions
-
Using Closures in C#
-
Performing Multiple Operations on a List Using Functors
-
-
Chapter 10 Regular Expressions
-
Introduction
-
Enumerating Matches
-
Extracting Groups from a MatchCollection
-
Verifying the Syntax of a Regular Expression
-
Quickly Finding Only the Last Match in a String
-
Augmenting the Basic String Replacement Function
-
Implementing a Better Tokenizer
-
Counting Lines of Text
-
Returning the Entire Line in Which a Match Is Found
-
Finding a Particular Occurrence of a Match
-
Using Common Patterns
-
-
Chapter 11 Data Structures and Algorithms
-
Introduction
-
Creating a Hash Code for a Data Type
-
Creating a Priority Queue
-
Creating a One-to-Many Map (MultiMap)
-
Creating a Binary Search Tree
-
Creating an n-ary Tree
-
Using a HashSet Object
-
-
Chapter 12 Filesystem I/O
-
Introduction
-
Manipulating File Attributes
-
Renaming a File
-
Outputting a Platform-Independent EOL Character
-
Manipulating Directory Attributes
-
Renaming a Directory
-
Searching for Directories or Files Using Wildcards
-
Obtaining the Directory Tree
-
Parsing a Path
-
Parsing Paths in Environment Variables
-
Launching and Interacting with Console Utilities
-
Locking Subsections of a File
-
Waiting for an Action to Occur in the Filesystem
-
Comparing Version Information of Two Executable Modules
-
Querying Information for All Drives on a System
-
Compressing and Decompressing Your Files
-
-
Chapter 13 Reflection
-
Introduction
-
Listing Referenced Assemblies
-
Listing Exported Types
-
Finding Overridden Methods
-
Finding Members in an Assembly
-
Determining and Obtaining Nested Types Within an Assembly
-
Displaying the Inheritance Hierarchy for a Type
-
Finding the Subclasses of a Type
-
Finding All Serializable Types Within an Assembly
-
Dynamically Invoking Members
-
Determining If a Type or Method Is Generic
-
Accessing Local Variable Information
-
Creating a Generic Type
-
-
Chapter 14 Web
-
Introduction
-
Converting an IP Address to a Hostname
-
Converting a Hostname to an IP Address
-
Parsing a URI
-
Handling Web Server Errors
-
Communicating with a Web Server
-
Going Through a Proxy
-
Obtaining the HTML from a URL
-
Using the Web Browser Control
-
Tying Database Tables to the Cache
-
Prebuilding an ASP.NET Web SiteProgrammatically
-
Escaping and Unescaping Data for the Web
-
Using the UriBuilder Class
-
Inspect and Change Your Web Application Configuration
-
Using Cached Results When Working with HTTP for Faster Performance
-
Checking Out a Web Server's Custom Error Pages
-
-
Chapter 15 xml
-
Introduction
-
Reading and Accessing XML Data in Document Order
-
Reading XML on the Web
-
Querying the Contents of an XML Document
-
Validating XML
-
Creating an XML Document Programmatically
-
Detecting Changes to an XML Document
-
Handling Invalid Characters in an XML String
-
Transforming XML
-
Tearing Apart an XML Document
-
Putting Together an XML Document
-
Validating Modified XML Documents Without Reloading
-
Extending Transformations
-
Getting Your Schemas in Bulk from Existing XML Files
-
Passing Parameters to Transformations
-
-
Chapter 16 Networking
-
Introduction
-
Writing a TCP Server
-
Writing a TCP Client
-
Simulating Form Execution
-
Transferring Data via HTTP
-
Using Named Pipes to Communicate
-
Pinging Programmatically
-
Send SMTP Mail Using the SMTP Service
-
Use Sockets to Scan the Ports on a Machine
-
Use the Current Internet Connection Settings
-
Transferring Files Using FTP
-
-
Chapter 17 Security
-
Introduction
-
Controlling Access to Types in a Local Assembly
-
Encrypting/Decrypting a String
-
Encrypting and Decrypting a File
-
Cleaning Up Cryptography Information
-
Verifying That a String Remains Uncorrupted Following Transmission
-
Storing Data Securely
-
Making a Security Assert Safe
-
Verifying That an Assembly Has Been Granted Specific Permissions
-
Minimizing the Attack Surface of an Assembly
-
Obtaining Security/Audit Information
-
Granting/Revoking Access to a File or Registry Key
-
Protecting String Data with Secure Strings
-
Securing Stream Data
-
Encrypting web.config Information
-
Obtaining the Full Reason a SecurityException Was Thrown
-
Achieving Secure Unicode Encoding
-
Obtaining a Safer File Handle
-
-
Chapter 18 Threading and Synchronization
-
Introduction
-
Creating Per-Thread Static Fields
-
Providing Thread-Safe Access to Class Members
-
Preventing Silent Thread Termination
-
Being Notified of the Completion of an Asynchronous Delegate
-
Storing Thread-Specific Data Privately
-
Granting Multiple Access to Resources with a Semaphore
-
Synchronizing Multiple Processes with the Mutex
-
Using Events to Make Threads Cooperate
-
Get the Naming Rights for Your Events
-
Performing Atomic Operations Among Threads
-
Optimizing Read-Mostly Access
-
-
Chapter 19 Toolbox
-
Introduction
-
Dealing with Operating System Shutdown, Power Management, or User Session Changes
-
Controlling a Service
-
List What Processes an Assembly Is Loaded In
-
Using Message Queues on a Local Workstation
-
Finding the Path to the Current Framework Version
-
Determining the Versions of an Assembly That Are Registered in the Global Assembly Cache (GAC)
-
Capturing Output from the Standard Output Stream
-
Running Code in Its Own AppDomain
-
Determining the Operating System and Service Pack Version of the Current Operating System
-
-
Chapter 20 Numbers and Enumerations
-
Introduction
-
Converting Between Degrees and Radians
-
Using the Bitwise Complement Operator with Various Data Types
-
Converting a Number in Another Base to Base10
-
Determining Whether a String Is a Valid Number
-
Rounding a Floating-Point Value
-
Choosing a Rounding Algorithm
-
Converting Between Temperature Scales
-
Safely Performing a Narrowing Numeric Cast
-
Displaying an Enumeration Value as a String
-
Converting Plain Text to an Equivalent Enumeration Value
-
Testing for a Valid Enumeration Value
-
Testing for a Valid Enumeration of Flags
-
Using Enumerated Members in a Bit Mask
-
Determining Whether One or More Enumeration Flags Are Set
-
Determining the Integral Part of a Decimal or Double
-
Product Details
- Title:
- C# 3.0 Cookbook, Third Edition
- By:
- Jay Hilyard, Stephen Teilhet
- Publisher:
- O'Reilly Media
- Formats:
-
- Ebook
- Safari Books Online
- Print Release:
- December 2007
- Ebook Release:
- December 2008
- Pages:
- 896
- Print ISBN:
- 978-0-596-51610-9
- | ISBN 10:
- 0-596-51610-X
- Ebook ISBN:
- 978-0-596-15860-6
- | ISBN 10:
- 0-596-15860-2
Customer Reviews
