Cover....1
Contributors....4
Copyright....3
Table of Contents....8
Preface....14
Chapter 1: Hello, C#! Welcome, .NET!....22
Introducing this book and its contents....22
Setting up your development environment....26
Understanding .NET....34
Building console apps using Visual Studio....39
Building console apps using VS Code....48
Making good use of the GitHub repository for this book....54
Looking for help....57
Practicing and exploring....72
Summary....75
Chapter 2: Speaking C#....78
Introducing the C# language....78
Discovering your C# compiler version....79
Understanding C# grammar and vocabulary....84
Working with variables....100
Exploring more about console apps....125
Practicing and exploring....143
Summary....145
Chapter 3: Controlling Flow, Converting Types, and Handling Exceptions....146
Operating on variables....146
Understanding selection statements....156
Understanding iteration statements....166
Storing multiple values in an array....169
Casting and converting between types....178
Handling exceptions....190
Checking for overflow....195
Practicing and exploring....198
Summary....200
Chapter 4: Writing, Debugging, and Testing Functions....202
Writing functions....202
Debugging during development....222
Hot reloading during development....232
Unit testing....234
Throwing and catching exceptions in functions....241
Practicing and exploring....250
Summary....251
Chapter 5: Building Your Own Types with Object-Oriented Programming....254
Talking about OOP....254
Building class libraries....256
Storing data in fields....266
Working with methods and tuples....283
Controlling access with properties and indexers....299
Pattern matching with objects....308
Working with record types....311
Practicing and exploring....319
Summary....321
Chapter 6: Implementing Interfaces and Inheriting Classes....322
Setting up a class library and console application....323
Static methods and overloading operators....325
Making types safely reusable with generics....333
Raising and handling events....336
Implementing interfaces....343
Working with null values....354
Inheriting from classes....365
Casting within inheritance hierarchies....373
Inheriting and extending .NET types....376
Summarizing custom type choices....382
Practicing and exploring....387
Summary....389
Chapter 7: Packaging and Distributing .NET Types....390
The road to .NET 9....390
Understanding .NET components....392
Publishing your code for deployment....407
Native ahead-of-time compilation....417
Packaging your libraries for NuGet distribution....422
Working with preview features....431
Practicing and exploring....433
Summary....436
Chapter 8: Working with Common .NET Types....438
Working with numbers....438
Working with text....447
Pattern matching with regular expressions....456
Storing multiple objects in collections....466
Working with spans, indexes, and ranges....490
Practicing and exploring....493
Summary....495
Chapter 9: Working with Files, Streams, and Serialization....498
Managing a filesystem....498
Reading and writing with streams....510
Encoding and decoding text....526
Serializing object graphs....530
Practicing and exploring....545
Summary....547
Chapter 10: Working with Data Using Entity Framework Core....548
Understanding modern databases....548
Setting up EF Core in a .NET project....554
Defining EF Core models....561
Querying EF Core models....577
Practicing and exploring....596
Summary....599
Chapter 11: Querying and Manipulating Data Using LINQ....600
Writing LINQ expressions....600
LINQ in practice....605
Sorting and more....611
Using LINQ with EF Core....619
Joining, grouping, and lookups....629
Practicing and exploring....636
Summary....638
Chapter 12: Introducing Modern Web Development Using .NET....640
Understanding ASP.NET Core....640
Structuring projects....649
Building an entity model for use in the rest of the book....653
Understanding web development....671
Practicing and exploring....675
Summary....677
Chapter 13: Building Websites Using ASP.NET Core....680
Exploring ASP.NET Core....680
History of Blazor....697
Exploring Blazor static SSR....700
Using Entity Framework Core with ASP.NET Core....711
Practicing and exploring....713
Summary....716
Chapter 14: Building Interactive Web Components Using Blazor....718
Reviewing the Blazor Web App project template....718
Building components using Blazor....733
Defining forms using the EditForm component....744
Practicing and exploring....750
Summary....753
Chapter 15: Building and Consuming Web Services....754
Building web services using ASP.NET Core....754
Creating a web service for the Northwind database....767
Documenting and trying out web services....779
Consuming web services using HTTP clients....789
Practicing and exploring....797
Summary....798
Epilogue....800
Next steps on your C# and .NET learning journey....800
The tenth edition for .NET 10....802
Good luck!....803
Index....806
An accessible guide for beginner-to-intermediate programmers to the concepts, real-world applications, and latest features of C# 13 and .NET 9, with hands-on exercises using Visual Studio and Visual Studio Code.
This Packt bestseller continues to be the definitive guide to modern cross-platform development. The 9th edition of C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals has been updated to cover the latest features and improvements in .NET 9 and C# 13. You'll start by mastering object-oriented programming, learning how to write, test, and debug functions, and implementing interfaces. You'll then dive into .NET APIs for data management, filesystem operations, and serialization. This latest edition integrates .NET 9 enhancements into its examples: faster exceptions and new LINQ methods. New ASP.NET Core 9 features include optimized static assets, built-in OpenAPI document generation, and the HybridCache. Practical examples, such as building websites and services with ASP.NET Core, have been refreshed to utilize the latest .NET 9 features. The book also introduces Blazor, with its new unified hosting model for unparalleled code reusability. With these updates, you'll learn how to build robust applications and services efficiently and effectively. By the end of this book, you'll have the knowledge and confidence to create professional and high-performance web applications using the latest technologies in C# 13 and .NET 9.
This book is aimed at beginner to intermediate-level C# and .NET developers. While prior exposure to C# or .NET is not a prerequisite, a general understanding of programming concepts will be beneficial. If you want to learn more technologies for building modern .NET projects like gRPC, SignalR, and .NET MAUI, read Mark's Apps and Services with .NET 8 book next; and if you aim to become a professional .NET developer quickly or mainly work on team projects, read his other book, Tools and Skills for .NET 8.