C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals - Eighth Edition

Book description

An accessible guide for beginner-to-intermediate programmers to the concepts, real-world applications, and latest features of C# 12 and .NET 8, with hands-on exercises using Visual Studio 2022 and Visual Studio Code.

Key Features

  • Explore the latest additions to C# 12, the .NET 8 class libraries, and Entity Framework Core 8
  • Create professional websites and services with ASP.NET Core 8 and Blazor
  • Build your confidence with step-by-step code examples and tips for best practices

Book Description

This latest edition of the bestselling Packt series will give you a solid foundation to start building projects using modern C# and .NET with confidence.

You'll learn about object-oriented programming; writing, testing, and debugging functions; and implementing interfaces. You'll take on .NET APIs for managing and querying data, working with the fi lesystem, and serialization. As you progress, you'll explore examples of cross-platform projects you can build and deploy, such as websites and services using ASP.NET Core.

This latest edition integrates .NET 8 enhancements into its examples: type aliasing and primary constructors for concise and expressive code. You'll handle errors robustly through the new built-in guard clauses and explore a simplified implementation of caching in ASP.NET Core 8.

If that's not enough, you'll also see how native ahead-of-time (AOT) compiler publish lets web services reduce memory use and run faster. You'll work with the seamless new HTTP editor in Visual Studio 2022 to enhance the testing and debugging process. You'll even get introduced to Blazor Full Stack with its new unified hosting model for unparalleled web development flexibility.

What you will learn

  • Discover C# 12's new features, including aliasing any type and primary constructors
  • Try out the native AOT publish capability for ASP.NET Core 8 Minimal APIs web services
  • Build rich web experiences using Blazor Full Stack, Razor Pages, and other ASP.NET Core features
  • Integrate and update databases in your apps using Entity Framework Core models
  • Query and manipulate data using LINQ
  • Build and consume powerful services using Web API and Minimal API

Who this book is for

This book is for beginners as well as intermediate-level C# and .NET programmers who have worked with C# in the past and want to catch up with the changes made in the last few years. Prior exposure to C# or .NET is not a prerequisite. A general understanding of programming will help you to work through the book more comfortably, though the content is suitable for those completely new to programming. If you already have some C# and .NET skills and want to focus on developing practical apps, you can pick up Mark’s other .NET book, Apps and Services with .NET 8, instead.

Table of contents

  1. Preface
    1. Where to find the code solutions
    2. What this book covers
    3. What you need for this book
    4. Get in touch
  2. Hello, C#! Welcome, .NET!
    1. Introducing this book and its contents
    2. Setting up your development environment
    3. Understanding .NET
    4. Building console apps using Visual Studio 2022
    5. Building console apps using Visual Studio Code
    6. Making good use of the GitHub repository for this book
    7. Looking for help
    8. Practicing and exploring
    9. Summary
    10. Learn more on Discord
  3. Speaking C#
    1. Introducing the C# language
    2. Discovering your C# compiler version
    3. Understanding C# grammar and vocabulary
    4. Working with variables
    5. Exploring more about console apps
    6. Understanding async and await
    7. Practicing and exploring
    8. Summary
  4. Controlling Flow, Converting Types, and Handling Exceptions
    1. Operating on variables
    2. Understanding selection statements
    3. Understanding iteration statements
    4. Storing multiple values in an array
    5. Casting and converting between types
    6. Handling exceptions
    7. Checking for overflow
    8. Practicing and exploring
    9. Summary
  5. Writing, Debugging, and Testing Functions
    1. Writing functions
    2. Debugging during development
    3. Hot reloading during development
    4. Logging during development and runtime
    5. Unit testing
    6. Throwing and catching exceptions in functions
    7. Practicing and exploring
    8. Summary
  6. Building Your Own Types with Object-Oriented Programming
    1. Talking about OOP
    2. Building class libraries
    3. Storing data in fields
    4. Working with methods and tuples
    5. Controlling access with properties and indexers
    6. Pattern matching with objects
    7. Working with record types
    8. Practicing and exploring
    9. Summary
  7. Implementing Interfaces and Inheriting Classes
    1. Setting up a class library and console application
    2. Static methods and overloading operators
    3. Making types safely reusable with generics
    4. Raising and handling events
    5. Implementing interfaces
    6. Managing memory with reference and value types
    7. Working with null values
    8. Inheriting from classes
    9. Casting within inheritance hierarchies
    10. Inheriting and extending .NET types
    11. Summarizing custom type choices
    12. Practicing and exploring
    13. Summary
  8. Packaging and Distributing .NET Types
    1. The road to .NET 8
    2. Understanding .NET components
    3. Publishing your code for deployment
    4. Native ahead-of-time compilation
    5. Decompiling .NET assemblies
    6. Packaging your libraries for NuGet distribution
    7. Working with preview features
    8. Practicing and exploring
    9. Summary
  9. Working with Common .NET Types
    1. Working with numbers
    2. Working with text
    3. Pattern matching with regular expressions
    4. Storing multiple objects in collections
    5. Working with spans, indexes, and ranges
    6. Practicing and exploring
    7. Summary
  10. Working with Files, Streams, and Serialization
    1. Managing the filesystem
    2. Reading and writing with streams
    3. Encoding and decoding text
    4. Serializing object graphs
    5. Working with environment variables
    6. Practicing and exploring
    7. Summary
  11. Working with Data Using Entity Framework Core
    1. Understanding modern databases
    2. Setting up EF Core in a .NET project
    3. Defining EF Core models
    4. Querying EF Core models
    5. Loading and tracking patterns with EF Core
    6. Modifying data with EF Core
    7. Practicing and exploring
    8. Summary
  12. Querying and Manipulating Data Using LINQ
    1. Writing LINQ expressions
    2. LINQ in practice
    3. Sorting and more
    4. Using LINQ with EF Core
    5. Joining, grouping, and lookups
    6. Aggregating and paging sequences
    7. Practicing and exploring
    8. Summary
  13. Introducing Web Development Using ASP.NET Core
    1. Understanding ASP.NET Core
    2. Structuring projects
    3. Building an entity model for use in the rest of the book
    4. Understanding web development
    5. Practicing and exploring
    6. Summary
  14. Building Websites Using ASP.NET Core Razor Pages
    1. Exploring ASP.NET Core
    2. Exploring ASP.NET Core Razor Pages
    3. Using Entity Framework Core with ASP.NET Core
    4. Configuring services and the HTTP request pipeline
    5. Practicing and exploring
    6. Summary
  15. Building and Consuming Web Services
    1. Building web services using the ASP.NET Core Web API
    2. Creating a web service for the Northwind database
    3. Documenting and testing web services
    4. Consuming web services using HTTP clients
    5. Practicing and exploring
    6. Summary
  16. Building User Interfaces Using Blazor
    1. History of Blazor
    2. Reviewing the Blazor Web App project template
    3. Building components using Blazor
    4. Enabling client-side execution using WebAssembly
    5. Practicing and exploring
    6. Summary
  17. Epilogue
    1. Next steps on your C# and .NET learning journey
    2. The ninth edition, coming November 2024
    3. Good luck!
  18. Index

Product information

  • Title: C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals - Eighth Edition
  • Author(s): Mark J. Price
  • Release date: November 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781837635870