Book description
Even if you're familiar with C# syntax, knowing how to combine various language features is a critical skill when you're building applications. This cookbook is packed full of recipes to help you solve issues for C# programming tasks you're likely to encounter. You'll learn tried-and-true techniques to help you achieve greater productivity and improve the quality of your code.
Author and independent consultant Joe Mayo shares some of the most important practices you'll need to be successful as a C# developer. Each section of this cookbook describes some useful facet of the C# programming language. These recipes--the result of many years of experience--are proven concepts for solving real-world problems with C#.
Recipes in this book will help you:
- Set up your project, manage object lifetime, and establish patterns
- Improve code quality through maintainability, error prevention, and correct syntax
- Use LINQ to Objects for in-memory data manipulation and querying
- Understand the differences between dynamic programming and reflection
- Apply several async programming features you may not be aware of
- Work with data using newer libraries and algorithms
- Learn different ways to use new C# features, such as pattern matching and records
Publisher resources
Table of contents
- Preface
-
1. Constructing Types and Apps
- 1.1. Managing Object End-of-Lifetime
- 1.2. Removing Explicit Dependencies
- 1.3. Delegating Object Creation to a Class
- 1.4. Delegating Object Creation to a Method
- 1.5. Designing Application Layers
- 1.6. Returning Multiple Values from a Method
- 1.7. Converting from Legacy to Strongly Typed Classes
- 1.8. Making Classes Adapt to Your Interface
- 1.9. Designing a Custom Exception
- 1.10. Constructing Objects with Complex Configuration
-
2. Coding Algorithms
- 2.1. Processing Strings Efficiently
- 2.2. Simplifying Instance Cleanup
- 2.3. Keeping Logic Local
- 2.4. Operating on Multiple Classes the Same Way
- 2.5. Checking for Type Equality
- 2.6. Processing Data Hierarchies
- 2.7. Converting from/to Unix Time
- 2.8. Caching Frequently Requested Data
- 2.9. Delaying Type Instantiation
- 2.10. Parsing Data Files
-
3. Ensuring Quality
- 3.1. Writing a Unit Test
- 3.2. Versioning Interfaces Safely
- 3.3. Simplifying Parameter Validation
- 3.4. Protecting Code from NullReferenceException
- 3.5. Avoiding Magic Strings
- 3.6. Customizing Class String Representation
- 3.7. Rethrowing Exceptions
- 3.8. Managing Process Status
- 3.9. Building Resilient Network Connections
- 3.10. Measuring Performance
- 4. Querying with LINQ
-
5. Implementing Dynamic and Reflection
- 5.1. Reading Attributes with Reflection
- 5.2. Accessing Type Members with Reflection
- 5.3. Instantiating Type Members with Reflection
- 5.4. Invoking Methods with Reflection
- 5.5. Replacing Reflection with Dynamic Code
- 5.6. Performing Interop with Office Apps
- 5.7. Creating an Inherently Dynamic Type
- 5.8. Adding and Removing Type Members Dynamically
- 5.9. Calling Python Code from C#
- 5.10. Calling C# Code from Python
-
6. Programming Asynchronously
- 6.1. Creating Async Console Applications
- 6.2. Reducing Memory Allocations for Async Return Values
- 6.3. Creating Async Iterators
- 6.4. Writing Safe Async Libraries
- 6.5. Updating Progress Asynchronously
- 6.6. Calling Synchronous Code from Async Code
- 6.7. Waiting for Parallel Tasks to Complete
- 6.8. Handling Parallel Tasks as They Complete
- 6.9. Cancelling Async Operations
- 6.10. Disposing of Async Resources
- 7. Manipulating Data
-
8. Matching with Patterns
- 8.1. Converting Instances Safely
- 8.2. Catching Filtered Exceptions
- 8.3. Simplifying Switch Assignments
- 8.4. Switching on Property Values
- 8.5. Switching on Tuples
- 8.6. Switching on Position
- 8.7. Switching on Value Ranges
- 8.8. Switching with Complex Conditions
- 8.9. Using Logical Conditions
- 8.10. Switching on Type
-
9. Examining Recent C# Language Highlights
- 9.1. Simplifying Application Startup
- 9.2. Reducing Instantiation Syntax
- 9.3. Initializing Immutable State
- 9.4. Creating Immutable Types
- 9.5. Simplifying Immutable Type Assignments
- 9.6. Designing for Record Reuse
- 9.7. Returning Different Method Override Types
- 9.8. Implementing Iterators as Extension Methods
- 9.9. Slicing Arrays
- 9.10. Initializing Entire Modules
- Summary
- Index
Product information
- Title: C# Cookbook
- Author(s):
- Release date: September 2021
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781492093695
You might also like
book
C# in Depth, Fourth Edition
C# in Depth, Fourth Edition is your key to unlocking the powerful new features added to …
book
Clean Code in C#
Develop your programming skills by exploring essential topics such as code reviews, implementing TDD and BDD, …
book
Code like a Pro in C#
Build on your existing programming skills and upskill to professional-level C# programming. In Code Like A …
book
Java Cookbook, 4th Edition
Java continues to grow and evolve, and this cookbook continues to evolve in tandem. With this …