Book description
Completely updated for C# 6.0, the new edition of this bestseller offers more than 150 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# 6.0 features. If you prefer solutions to general C# language instruction and quick answers to theory, this is your book.
Publisher resources
Table of contents
- Preface
-
Classes and Generics
- 1.0. Introduction
- 1.1. Creating Union-Type Structures
- 1.2. Making a Type Sortable
- 1.3. Making a Type Searchable
- 1.4. Returning Multiple Items from a Method
- 1.5. Parsing Command-Line Parameters
- 1.6. Initializing a Constant Field at Runtime
- 1.7. Building Cloneable Classes
- 1.8. Ensuring an Object’s Disposal
- 1.9. Deciding When and Where to Use Generics
- 1.10. Understanding Generic Types
- 1.11. Reversing the Contents of a Sorted List
- 1.12. Constraining Type Arguments
- 1.13. Initializing Generic Variables to Their Default Values
- 1.14. Adding Hooks to Generated Entities
- 1.15. Controlling How a Delegate Fires Within a Multicast Delegate
- 1.16. Using Closures in C#
- 1.17. Performing Multiple Operations on a List Using Functors
- 1.18. Controlling Struct Field Initialization
- 1.19. Checking for null in a More Concise Way
-
Collections, Enumerators, and Iterators
- 2.0. Introduction
- 2.1. Looking for Duplicate Items in a List<T>
- 2.2. Keeping Your List<T> Sorted
- 2.3. Sorting a Dictionary’s Keys and/or Values
- 2.4. Creating a Dictionary with Min and Max Value Boundaries
- 2.5. Persisting a Collection Between Application Sessions
- 2.6. Testing Every Element in an Array or List<T>
- 2.7. Creating Custom Enumerators
- 2.8. Dealing with finally Blocks and Iterators
- 2.9. Implementing Nested foreach Functionality in a Class
- 2.10. Using a Thread-Safe Dictionary for Concurrent Access Without Manual Locking
-
Data Types
- 3.0. Introduction
- 3.1. Encoding Binary Data as Base64
- 3.2. Decoding a Base64-Encoded Binary
- 3.3. Converting a String Returned as a Byte[] Back into a String
- 3.4. Passing a String to a Method That Accepts Only a Byte[]
- 3.5. Determining Whether a String Is a Valid Number
- 3.6. Rounding a Floating-Point Value
- 3.7. Choosing a Rounding Algorithm
- 3.8. Safely Performing a Narrowing Numeric Cast
- 3.9. Testing for a Valid Enumeration Value
- 3.10. Using Enumerated Members in a Bit Mask
- 3.11. Determining Whether One or More Enumeration Flags Are Set
-
Language Integrated Query (LINQ) and Lambda Expressions
- 4.0. Introduction
- 4.1. Querying a Message Queue
- 4.2. Using Set Semantics with Data
- 4.3. Reusing Parameterized Queries with LINQ to SQL
- 4.4. Sorting Results in a Culture-Sensitive Manner
- 4.5. Adding Functional Extensions for Use with LINQ
- 4.6. Querying and Joining Across Data Repositories
- 4.7. Querying Configuration Files with LINQ
- 4.8. Creating XML Straight from a Database
- 4.9. Being Selective About Your Query Results
- 4.10. Using LINQ with Collections That Don’t Support IEnumerable<T>
- 4.11. Performing an Advanced Interface Search
- 4.12. Using Lambda Expressions
- 4.13. Using Different Parameter Modifiers in Lambda Expressions
- 4.14. Speeding Up LINQ Operations with Parallelism
-
Debugging and Exception Handling
- 5.0. Introduction
- 5.1. Knowing When to Catch and Rethrow Exceptions
- 5.2. Handling Exceptions Thrown from Methods Invoked via Reflection
- 5.3. Creating a New Exception Type
- 5.4. Breaking on a First-Chance Exception
- 5.5. Handling Exceptions Thrown from an Asynchronous Delegate
- 5.6. Giving Exceptions the Extra Info They Need with Exception.Data
- 5.7. Dealing with Unhandled Exceptions in WinForms Applications
- 5.8. Dealing with Unhandled Exceptions in WPF Applications
- 5.9. Determining Whether a Process Has Stopped Responding
- 5.10. Using Event Logs in Your Application
- 5.11. Watching the Event Log for a Specific Entry
- 5.12. Implementing a Simple Performance Counter
- 5.13. Creating Custom Debugging Displays for Your Classes
- 5.14. Tracking Where Exceptions Come From
- 5.15. Handling Exceptions in Asynchronous Scenarios
- 5.16. Being Selective About Exception Processing
-
Reflection and Dynamic Programming
- 6.0. Introduction
- 6.1. Listing Referenced Assemblies
- 6.2. Determining Type Characteristics in Assemblies
- 6.3. Determining Inheritance Characteristics
- 6.4. Invoking Members Using Reflection
- 6.5. Accessing Local Variable Information
- 6.6. Creating a Generic Type
- 6.7. Using dynamic Versus object
- 6.8. Building Objects Dynamically
- 6.9. Make Your Objects Extensible
-
Regular Expressions
- 7.0. Introduction
- 7.1. Extracting Groups from a MatchCollection
- 7.2. Verifying the Syntax of a Regular Expression
- 7.3. Augmenting the Basic String Replacement Function
- 7.4. Implementing a Better Tokenizer
- 7.5. Returning the Entire Line in Which a Match Is Found
- 7.6. Finding a Particular Occurrence of a Match
- 7.7. Using Common Patterns
-
Filesystem I/O
- 8.0. Introduction
- 8.1. Searching for Directories or Files Using Wildcards
- 8.2. Obtaining the Directory Tree
- 8.3. Parsing a Path
- 8.4. Launching and Interacting with Console Utilities
- 8.5. Locking Subsections of a File
- 8.6. Waiting for an Action to Occur in the Filesystem
- 8.7. Comparing Version Information of Two Executable Modules
- 8.8. Querying Information for All Drives on a System
- 8.9. Compressing and Decompressing Your Files
-
Networking and Web
- 9.0. Introduction
- 9.1. Handling Web Server Errors
- 9.2. Communicating with a Web Server
- 9.3. Going Through a Proxy
- 9.4. Obtaining the HTML from a URL
- 9.5. Using the Web Browser Control
- 9.6. Prebuilding an ASP.NET Website Programmatically
- 9.7. Escaping and Unescaping Data for the Web
- 9.8. Checking Out a Web Server’s Custom Error Pages
- 9.9. Writing a TCP Server
- 9.10. Writing a TCP Client
- 9.11. Simulating Form Execution
- 9.12. Transferring Data via HTTP
- 9.13. Using Named Pipes to Communicate
- 9.14. Pinging Programmatically
- 9.15. Sending SMTP Mail Using the SMTP Service
- 9.16. Using Sockets to Scan the Ports on a Machine
- 9.17. Using the Current Internet Connection Settings
- 9.18. Transferring Files Using FTP
-
XML
- 10.0. Introduction
- 10.1. Reading and Accessing XML Data in Document Order
- 10.2. Querying the Contents of an XML Document
- 10.3. Validating XML
- 10.4. Detecting Changes to an XML Document
- 10.5. Handling Invalid Characters in an XML String
- 10.6. Transforming XML
- 10.7. Validating Modified XML Documents Without Reloading
- 10.8. Extending Transformations
- 10.9. Getting Your Schemas in Bulk from Existing XML Files
- 10.10. Passing Parameters to Transformations
-
Security
- 11.0. Introduction
- 11.1. Encrypting and Decrypting a String
- 11.2. Encrypting and Decrypting a File
- 11.3. Cleaning Up Cryptography Information
- 11.4. Preventing String Tampering in Transit or at Rest
- 11.5. Making a Security Assert Safe
- 11.6. Verifying That an Assembly Has Been Granted Specific Permissions
- 11.7. Minimizing the Attack Surface of an Assembly
- 11.8. Obtaining Security and/or Audit Information
- 11.9. Granting or Revoking Access to a File or Registry Key
- 11.10. Protecting String Data with Secure Strings
- 11.11. Securing Stream Data
- 11.12. Encrypting web.config Information
- 11.13. Obtaining a Safer File Handle
- 11.14. Storing Passwords
-
Threading, Synchronization, and Concurrency
- 12.0. Introduction
- 12.1. Creating Per-Thread Static Fields
- 12.2. Providing Thread-Safe Access to Class Members
- 12.3. Preventing Silent Thread Termination
- 12.4. Being Notified of the Completion of an Asynchronous Delegate
- 12.5. Storing Thread-Specific Data Privately
- 12.6. Granting Multiple Access to Resources with a Semaphore
- 12.7. Synchronizing Multiple Processes with the Mutex
- 12.8. Using Events to Make Threads Cooperate
- 12.9. Performing Atomic Operations Among Threads
- 12.10. Optimizing Read-Mostly Access
- 12.11. Making Your Database Requests More Scalable
- 12.12. Running Tasks in Order
-
Toolbox
- 13.0. Introduction
- 13.1. Dealing with Operating System Shutdown, Power Management, or User Session Changes
- 13.2. Controlling a Service
- 13.3. List What Processes an Assembly Is Loaded In
- 13.4. Using Message Queues on a Local Workstation
- 13.5. Capturing Output from the Standard Output Stream
- 13.6. Capturing Standard Output for a Process
- 13.7. Running Code in Its Own AppDomain
- 13.8. Determining the Operating System and Service Pack Version of the Current Operating System
- Index
Product information
- Title: C# 6.0 Cookbook, 4th Edition
- Author(s):
- Release date: October 2015
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491921463
You might also like
book
C# 4.0 in a Nutshell, 4th Edition
What people are saying about C# 4.0 in a Nutshell "C# 4.0 in a Nutshell is …
book
C# in a Nutshell, Second Edition
C# in a Nutshell provides C# programmers with a concise and thorough reference to the language …
book
C# Programming Cookbook
Quick fixes to your common C# programming problems, with a focus on C# 6.0 About This …
video
C# 8 and .NET Core 3.1 Recipes - Second Edition
C# is a multi-paradigm programming language providing support for software engineering principles such as strong type …