Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Joe Mayo

Rating No ratings yet

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

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A recipe-driven guide to writing professional-grade C#: each short, self-contained solution shows how to combine language features—dependency injection, LINQ, async, pattern matching, records—into maintainable real-world code. Best for developers who already know C# syntax and want proven patterns for structuring apps, not a beginner's tutorial. 【Book Arc】 - **Opening (~0%–10%)**: Orients you to the cookbook's philosophy—recipes as composable solutions—and previews the full problem space from project setup through modern language features. - **Early (~10%–30%)**: Constructing types and apps: object lifetime and disposal, IoC containers and dependency injection, project/layer layout, custom exceptions, and generic collections. - **Early–Middle (~30%–45%)**: Coding algorithms: performance-minded techniques, interface-based polymorphism to avoid branching spaghetti, custom equality for collections, and caching frequently requested data. - **Middle (~45%–55%)**: Manipulating data: parsing irregular text and legacy formats with regular expressions, plus in-memory querying and transformation of flat data into hierarchical structures. - **Late (~55%–80%)**: Async programming (handling parallel tasks as they complete, cancellation, disposing async resources) and the LINQ-to-Objects toolchain for querying and shaping data. - **Ending (~80%–100%)**: Recent C# language highlights—pattern matching (position, ranges, complex conditions, type), records and immutability, simplified startup and instantiation, iterators as extension methods, and array slicing. 【Key Takeaways】 - **Dependency injection is the backbone of maintainable apps** (Early): registering services in an IoC container and injecting them via constructors decouples types, centralizes instantiation, and makes code unit-testable. - **Object lifetime is a design decision, not an afterthought** (Early): choosing transient, singleton, or scoped registration—and implementing the dispose pattern correctly—prevents unpredictable errors like ObjectDisposedException. - **Polymorphism beats branching** (Early–Middle): programming against interfaces such as IInvoice lets you extend behavior by adding types instead of editing if/switch logic, keeping maintenance localized. - **Return abstractions, not concrete collections** (Middle): exposing IEnumerable<T> from methods frees callers from assumptions about the underlying collection and lets implementations change without breaking signatures. - **Custom equality unlocks collection searches** (Middle): when default equality fails, implementing type equality is what makes searching and deduplication in collections actually work. - **Regex is the pragmatic bridge for messy data** (Middle): legacy files, logs, and non-standard formats can be ingested and reshaped into typed objects without modifying the source system. - **Async has subtleties worth mastering** (Late): processing parallel tasks as they complete, cancelling operations, and disposing async resources are distinct skills beyond basic await. - **Modern C# features reward deliberate use** (Ending): pattern matching, records, and immutability simplify startup, reduce boilerplate, and encode intent—but each has design trade-offs the recipes illustrate. 【Reading Tips】 - Treat this as a reference, not a linear read: jump to the recipe matching your current problem, then follow the "See Also" cross-references to related patterns. - Deep-read the early chapters on DI, object lifetime, and disposal—these foundational choices ripple through everything else. - Skim the algorithm and data chapters if you already know LINQ and regex well, but pause on the equality and caching recipes, which are commonly underestimated. - For the async and modern-language chapters, type out the examples rather than reading passively; the subtleties (cancellation, disposal, record reuse) only land in practice. - Keep the companion code repository open alongside the book and adapt recipes to your own domain rather than copying verbatim. 【Coverage Limits】 The excerpts cover the table of contents, preface, and selected recipes from the early through middle chapters, with only chapter titles visible for the async, data, and modern-language sections; specific recipes in those later chapters are not detailed here.
Page 7
. . . . . . . . . . . . . . . . . . . . . . . . . . 215 7.1 Generating Password Hashes 215 7.2 Encrypting and Decrypting Secrets 219 7.3 Hiding Development S...
View in text
Excerpt 2
verts services, a ServiceCollection, into a ServiceProvider. The term IoC container refers to this ServiceProvider instance— it instantiates and locates type...
View in text
Excerpt 3
pter discuss application performance, such as the efficient handling of strings, caching data, or delaying the instantiation of a type until you need it. In...
View in text
Excerpt 4
+?::(?<created>.+?)::(?<items>.+?)::(?<customer>.+?)::.+"); foreach (var invoiceString in invoiceFile.Split('\n')) { Match match = invoiceRegEx.Match(invoice...
View in text
Excerpt 5
00; const int RetryCount = 3; bool success = false; int tryCount = 0; try { do { try { Console.WriteLine("Getting Orders"); await GetOrdersAsync(); success =...
View in text
Excerpt 6
tResults(List<SalesPerson> salesPeople, string title) { Console.WriteLine($"\n{title}\n"); salesPeople.ForEach(person => Console.WriteLine($"{person.ID}. {pe...
View in text
Excerpt 7
om detail in details.Values let length = detail.Attribute.Name.Length select "".PadLeft(length, '-')); header.Append("\n"); return header; } protected overri...
View in text
Excerpt 8
e CPU architectures. One of the TPL primitives was the Task class, which represented a promise to perform some work, on a separate thread, and return the res...
View in text
Tags
AI categories
Programming LanguageC++C#
ISBN: 1492093696
Publisher: O'Reilly Media
Publish Year: 2021
Language: English
Pages: 328
File Format: PDF
File Size: 5.1 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…