C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals - Seventh Edition

Book description

Publisher’s Note: Microsoft will stop supporting .NET 7 from May 2024. The newer 8th edition of the book is available that covers .NET 8 (end-of-life November 2026) with C# 12 and EF Core. Purchase of the print or Kindle book includes a free PDF eBook

Key Features

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

Book Description

Extensively revised to accommodate the latest features that come with C# 11 and .NET 7, this latest edition of our guide will get you coding in C# with confidence.

You’ll learn object-oriented programming, writing, testing, and debugging functions, implementing interfaces, and inheriting classes. Next, you’ll take on .NET APIs for performing tasks like managing and querying data, working with the filesystem, and serialization. As you progress, you’ll also explore examples of cross-platform projects you can build and deploy, such as websites and services using ASP.NET Core.

Instead of distracting you with unnecessary graphical user interface code, the first eleven chapters will teach you about C# language constructs and many of the .NET libraries through simple console applications. Having mastered the basics, you’ll then start building websites, web services, and browser apps.

By the end of this book, you’ll be able to create rich web experiences and have a solid grasp of object-oriented programming that you can build upon.

What you will learn

  • Build rich web experiences using Blazor, Razor Pages, the Model-View-Controller (MVC) pattern, and other features of ASP.NET Core
  • Write, test, and debug functions
  • Query and manipulate data using LINQ
  • Integrate and update databases in your apps using Entity Framework Core models
  • Build and consume powerful services using the latest technologies, including Web API and Minimal API
  • For .NET 6 developers:
  • C# 11 can be used with .NET 6, including features like raw string literals
  • EF Core 7 targets .NET 6, so you can benefit from its new features like ExecuteUpdate and ExecuteDelete for more efficient data modifications

Who this book is for

This book is primarily for beginners, but 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 past few years will also find plenty of useful information in it. Prior exposure to C# or .NET is not a prerequisite, but you should have a general understanding of programming before you jump in. If you already have some C# and .NET skills and want to focus on developing apps, we recommend that you pick up Mark’s other .NET book, Apps and Services with .NET 7, 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. Setting up your development environment
      1. Choosing the appropriate tool and application type for learning
        1. Pros and cons of the .NET Interactive Notebooks extension
        2. Using Visual Studio Code for cross-platform development
        3. Using GitHub Codespaces for development in the cloud
        4. Using Visual Studio for Mac for general development
        5. Using Visual Studio for Windows for general development
        6. What I used
      2. Deploying cross-platform
      3. Downloading and installing Visual Studio 2022 for Windows
        1. Microsoft Visual Studio for Windows keyboard shortcuts
      4. Downloading and installing Visual Studio Code
        1. Installing other extensions
        2. Managing Visual Studio Code extensions at the command line
        3. Understanding Microsoft Visual Studio Code versions
        4. Microsoft Visual Studio Code keyboard shortcuts
    2. Understanding .NET
      1. Understanding .NET Framework
      2. Understanding the Mono, Xamarin, and Unity projects
      3. Understanding .NET Core
      4. Understanding the journey to one .NET
        1. Understanding Blazor WebAssembly versioning
      5. Understanding .NET support
        1. Understanding .NET Runtime and .NET SDK versions
        2. Listing and removing versions of .NET
      6. What is different about modern .NET?
        1. Windows desktop development
        2. Web development
        3. Database development
      7. Understanding .NET Standard
      8. .NET platforms and tools used by the C# and .NET book editions
      9. Topics covered by Apps and Services with .NET 7
      10. Understanding intermediate language
      11. Comparing .NET technologies
    3. Building console apps using Visual Studio 2022
      1. Managing multiple projects using Visual Studio 2022
      2. Writing code using Visual Studio 2022
      3. Compiling and running code using Visual Studio
        1. Understanding the compiler-generated folders and files
      4. Understanding top-level programs
        1. Implicitly imported namespaces
        2. Revealing the hidden code by throwing an exception
      5. Adding a second project using Visual Studio 2022
    4. Building console apps using Visual Studio Code
      1. Managing multiple projects using Visual Studio Code
      2. Writing code using Visual Studio Code
      3. Compiling and running code using the dotnet CLI
      4. Adding a second project using Visual Studio Code
    5. Exploring code using .NET Interactive Notebooks
      1. Using .NET Interactive Notebooks for the code in this book
    6. Reviewing the folders and files for projects
      1. Understanding the common folders and files
      2. Understanding the solution code on GitHub
    7. Making good use of the GitHub repository for this book
      1. Raising issues with the book
      2. Giving me feedback
      3. Downloading solution code from the GitHub repository
      4. Using Git with Visual Studio Code and the command line
        1. Cloning the book solution code repository
    8. Looking for help
      1. Reading Microsoft documentation
      2. Getting help for the dotnet tool
      3. Getting definitions of types and their members
      4. Looking for answers on Stack Overflow
      5. Searching for answers using Google
      6. Subscribing to the official .NET blog
      7. Watching Scott Hanselman’s videos
      8. A companion book to continue your learning journey
    9. Practicing and exploring
      1. Exercise 1.1 – Test your knowledge
      2. Exercise 1.2 – Practice C# anywhere with a browser
      3. Exercise 1.3 – Explore topics
      4. Exercise 1.4 – Explore themes of modern .NET
    10. Summary
  3. Speaking C#
    1. Introducing the C# language
      1. Understanding language versions and features
        1. Project COOL
        2. C# 1
        3. C# 1.2
        4. C# 2
        5. C# 3
        6. C# 4
        7. C# 5
        8. C# 6
        9. C# 7.0
        10. C# 7.1
        11. C# 7.2
        12. C# 7.3
        13. C# 8
        14. C# 9
        15. C# 10
        16. C# 11
      2. Understanding C# standards
      3. Discovering your C# compiler versions
        1. How to output the SDK version
        2. Enabling a specific language version compiler
        3. Switching the C# compiler for .NET 6
    2. Understanding C# grammar and vocabulary
      1. Showing the compiler version
      2. Understanding C# grammar
      3. Statements
      4. Comments
      5. Blocks
      6. Examples of statements and blocks
      7. Understanding C# vocabulary
      8. Comparing programming languages to human languages
      9. Changing the color scheme for C# syntax
      10. Help for writing correct code
      11. Importing namespaces
      12. Implicitly and globally importing namespaces
      13. Verbs are methods
      14. Nouns are types, variables, fields, and properties
      15. Revealing the extent of the C# vocabulary
    3. Working with variables
      1. Naming things and assigning values
      2. Literal values
      3. Storing text
        1. Verbatim strings
        2. Raw string literals
        3. Raw interpolated string literals
        4. Summarizing options for storing text
      4. Storing numbers
        1. Storing whole numbers
        2. Exploring whole numbers
      5. Storing real numbers
        1. Writing code to explore number sizes
        2. Comparing double and decimal types
      6. Storing Booleans
      7. Storing any type of object
      8. Storing dynamic types
      9. Declaring local variables
        1. Specifying the type of a local variable
        2. Inferring the type of a local variable
        3. Using target-typed new to instantiate objects
      10. Getting and setting the default values for types
    4. Exploring more about console apps
      1. Displaying output to the user
        1. Formatting using numbered positional arguments
        2. Formatting using interpolated strings
        3. Understanding format strings
      2. Getting text input from the user
      3. Simplifying the usage of the console
        1. Importing a static type for a single file
        2. Importing a static type for all code files in a project
      4. Getting key input from the user
      5. Passing arguments to a console app
      6. Setting options with arguments
      7. Handling platforms that do not support an API
    5. Understanding async and await
      1. Improving responsiveness for console apps
    6. Practicing and exploring
      1. Exercise 2.1 – Test your knowledge
      2. Exercise 2.2 – Test your knowledge of number types
      3. Exercise 2.3 – Practice number sizes and ranges
      4. Exercise 2.4 – Explore topics
    7. Summary
  4. Controlling Flow, Converting Types, and Handling Exceptions
    1. Operating on variables
      1. Exploring unary operators
      2. Exploring binary arithmetic operators
      3. Assignment operators
      4. Exploring logical operators
      5. Exploring conditional logical operators
      6. Exploring bitwise and binary shift operators
      7. Miscellaneous operators
    2. Understanding selection statements
      1. Branching with the if statement
        1. Why you should always use braces with if statements
      2. Pattern matching with the if statement
      3. Branching with the switch statement
      4. Pattern matching with the switch statement
      5. Simplifying switch statements with switch expressions
    3. Understanding iteration statements
      1. Looping with the while statement
      2. Looping with the do statement
      3. Looping with the for statement
      4. Looping with the foreach statement
        1. Understanding how foreach works internally
    4. Storing multiple values in an array
      1. Working with single-dimensional arrays
      2. Working with multi-dimensional arrays
      3. Working with jagged arrays
      4. List pattern matching with arrays
      5. Summarizing arrays
    5. Casting and converting between types
      1. Casting numbers implicitly and explicitly
      2. Converting with the System.Convert type
      3. Rounding numbers
        1. Understanding the default rounding rules
      4. Taking control of rounding rules
      5. Converting from any type to a string
      6. Converting from a binary object to a string
      7. Parsing from strings to numbers or dates and times
        1. Errors using Parse
        2. Avoiding exceptions using the TryParse method
    6. Handling exceptions
      1. Wrapping error-prone code in a try block
        1. Catching all exceptions
        2. Catching specific exceptions
        3. Catching with filters
    7. Checking for overflow
      1. Throwing overflow exceptions with the checked statement
      2. Disabling compiler overflow checks with the unchecked statement
    8. Practicing and exploring
      1. Exercise 3.1 – Test your knowledge
      2. Exercise 3.2 – Explore loops and overflow
      3. Exercise 3.3 – Practice loops and operators
      4. Exercise 3.4 – Practice exception handling
      5. Exercise 3.5 – Test your knowledge of operators
      6. Exercise 3.6 – Explore topics
    9. Summary
  5. Writing, Debugging, and Testing Functions
    1. Writing functions
      1. Understanding top-level programs and functions
      2. Times table example
        1. Writing a times table function
      3. A brief aside about arguments and parameters
      4. Writing a function that returns a value
        1. Converting numbers from cardinal to ordinal
      5. Calculating factorials with recursion
      6. Documenting functions with XML comments
      7. Using lambdas in function implementations
    2. Debugging during development
      1. Using the Visual Studio Code integrated terminal during debugging
      2. Creating code with a deliberate bug
      3. Setting a breakpoint and starting debugging
        1. Using Visual Studio 2022
      4. Navigating with the debugging toolbar
        1. Using Visual Studio Code
      5. Debugging windows
      6. Stepping through code
      7. Customizing breakpoints
    3. Hot reloading during development
      1. Hot reloading using Visual Studio 2022
      2. Hot reloading using Visual Studio Code and the command line
    4. Logging during development and runtime
      1. Understanding logging options
      2. Instrumenting with Debug and Trace
        1. Writing to the default trace listener
      3. Configuring trace listeners
      4. Switching trace levels
        1. Adding packages to a project in Visual Studio 2022
        2. Adding packages to a project in Visual Studio Code
        3. Reviewing project packages
      5. Logging information about your source code
    5. Unit testing
      1. Understanding types of testing
      2. Creating a class library that needs testing
      3. Writing unit tests
        1. Running unit tests using Visual Studio 2022
        2. Running unit tests using Visual Studio Code
        3. Fixing the bug
    6. Throwing and catching exceptions in functions
      1. Understanding usage errors and execution errors
      2. Commonly thrown exceptions in functions
      3. Understanding the call stack
      4. Where to catch exceptions
      5. Rethrowing exceptions
      6. Implementing the tester-doer pattern
        1. Problems with the tester-doer pattern
    7. Practicing and exploring
      1. Exercise 4.1 – Test your knowledge
      2. Exercise 4.2 – Practice writing functions with debugging and unit testing
      3. Exercise 4.3 – Explore topics
    8. Summary
  6. Building Your Own Types with Object-Oriented Programming
    1. Talking about OOP
    2. Building class libraries
      1. Creating a class library
      2. Defining a class in a namespace
      3. Understanding members
      4. Instantiating a class
      5. Importing a namespace to use a type
        1. Avoiding a namespace conflict with a using alias
        2. Renaming a type with a using alias
      6. Understanding objects
        1. Inheriting from System.Object
    3. Storing data within fields
      1. Defining fields
      2. Understanding access modifiers
      3. Setting and outputting field values
      4. Storing a value using an enum type
      5. Storing multiple values using an enum type
      6. Storing multiple values using collections
      7. Understanding generic collections
      8. Making a field static
      9. Making a field constant
      10. Making a field read-only
      11. Initializing fields with constructors
        1. Defining multiple constructors
    4. Writing and calling methods
      1. Returning values from methods
      2. Combining multiple returned values using tuples
        1. C# language support for tuples
        2. Naming the fields of a tuple
        3. Deconstructing tuples
        4. Deconstructing types
      3. Defining and passing parameters to methods
      4. Overloading methods
      5. Passing optional and named parameters
        1. Naming parameter values when calling methods
      6. Controlling how parameters are passed
        1. Simplified out parameters
      7. Understanding ref returns
    5. Splitting classes using partial
    6. Controlling access with properties and indexers
      1. Defining read-only properties
      2. Defining settable properties
      3. Requiring properties to be set during instantiation
      4. Defining indexers
    7. More about methods
      1. Implementing functionality using methods
      2. Implementing functionality using operators
      3. Implementing functionality using local functions
    8. Pattern matching with objects
      1. Defining flight passengers
      2. Enhancements to pattern matching in C# 9 or later
    9. Working with records
      1. Init-only properties
      2. Understanding records
      3. Positional data members in records
        1. Simplifying data members in records
    10. Practicing and exploring
      1. Exercise 5.1 – Test your knowledge
      2. Exercise 5.2 – Explore topics
    11. Summary
  7. Implementing Interfaces and Inheriting Classes
    1. Setting up a class library and console application
    2. Making types safely reusable with generics
      1. Working with non-generic types
      2. Working with generic types
    3. Raising and handling events
      1. Calling methods using delegates
      2. Defining and handling delegates
      3. Defining and handling events
    4. Implementing interfaces
      1. Common interfaces
      2. Comparing objects when sorting
      3. Comparing objects using a separate class
      4. Implicit and explicit interface implementations
      5. Defining interfaces with default implementations
    5. Managing memory with reference and value types
      1. Defining reference and value types
      2. How reference and value types are stored in memory
      3. Equality of types
      4. Defining struct types
      5. Defining record struct types
      6. Releasing unmanaged resources
      7. Ensuring that Dispose is called
    6. Working with null values
      1. Making a value type nullable
      2. Understanding null-related initialisms
      3. Understanding nullable reference types
      4. Controlling the nullability warning check feature
      5. Declaring non-nullable variables and parameters
      6. Checking for null
      7. Checking for null in method parameters
    7. Inheriting from classes
      1. Extending classes to add functionality
      2. Hiding members
      3. Overriding members
      4. Inheriting from abstract classes
      5. Preventing inheritance and overriding
      6. Understanding polymorphism
    8. Casting within inheritance hierarchies
      1. Implicit casting
      2. Explicit casting
      3. Avoiding casting exceptions
        1. Using is to check a type
        2. Using as to cast a type
    9. Inheriting and extending .NET types
      1. Inheriting exceptions
      2. Extending types when you can’t inherit
        1. Using static methods to reuse functionality
        2. Using extension methods to reuse functionality
    10. Writing better code
      1. Treating warnings as errors
      2. Understanding warning waves
      3. Using an analyzer to write better code
        1. Suppressing warnings
        2. Fixing the code
        3. Understanding common StyleCop recommendations
    11. Practicing and exploring
      1. Exercise 6.1 – Test your knowledge
      2. Exercise 6.2 – Practice creating an inheritance hierarchy
      3. Exercise 6.3 – Explore topics
    12. Summary
  8. Packaging and Distributing .NET Types
    1. The road to .NET 7
      1. .NET Core 1.0
      2. .NET Core 1.1
      3. .NET Core 2.0
      4. .NET Core 2.1
      5. .NET Core 2.2
      6. .NET Core 3.0
      7. .NET Core 3.1
      8. .NET 5.0
      9. .NET 6.0
      10. .NET 7.0
      11. Improving performance with .NET 5 and later
      12. Checking your .NET SDKs for updates
    2. Understanding .NET components
      1. Assemblies, NuGet packages, and namespaces
        1. What is a namespace?
        2. Dependent assemblies
      2. Microsoft .NET project SDKs
      3. Namespaces and types in assemblies
      4. NuGet packages
      5. Understanding frameworks
      6. Importing a namespace to use a type
      7. Relating C# keywords to .NET types
        1. Mapping C# aliases to .NET types
        2. Understanding native-sized integers
        3. Revealing the location of a type
      8. Sharing code with legacy platforms using .NET Standard
      9. Understanding defaults for class libraries with different SDKs
      10. Creating a .NET Standard 2.0 class library
      11. Controlling the .NET SDK
    3. Publishing your code for deployment
      1. Creating a console app to publish
      2. Understanding dotnet commands
        1. Creating new projects
      3. Getting information about .NET and its environment
      4. Managing projects
      5. Publishing a self-contained app
      6. Publishing a single-file app
      7. Reducing the size of apps using app trimming
        1. Enabling assembly-level trimming
        2. Enabling type-level and member-level trimming
    4. Decompiling .NET assemblies
      1. Decompiling using the ILSpy extension for Visual Studio 2022
      2. Viewing source links with Visual Studio 2022
      3. No, you cannot technically prevent decompilation
    5. Packaging your libraries for NuGet distribution
      1. Referencing a NuGet package
        1. Fixing dependencies
      2. Packaging a library for NuGet
        1. Publishing a package to a public NuGet feed
        2. Publishing a package to a private NuGet feed
      3. Exploring NuGet packages with a tool
      4. Testing your class library package
    6. Porting from .NET Framework to modern .NET
      1. Could you port?
      2. Should you port?
      3. Differences between .NET Framework and modern .NET
      4. .NET Portability Analyzer
      5. .NET Upgrade Assistant
      6. Using non-.NET Standard libraries
    7. Working with preview features
      1. Requiring preview features
      2. Enabling preview features
    8. Practicing and exploring
      1. Exercise 7.1 – Test your knowledge
      2. Exercise 7.2 – Explore topics
      3. Exercise 7.3 – Explore PowerShell
    9. Summary
  9. Working with Common .NET Types
    1. Working with numbers
      1. Working with big integers
      2. Working with complex numbers
      3. Understanding quaternions
      4. Generating random numbers for games and similar apps
    2. Working with text
      1. Getting the length of a string
      2. Getting the characters of a string
      3. Splitting a string
      4. Getting part of a string
      5. Checking a string for content
      6. Joining, formatting, and other string members
      7. Building strings efficiently
    3. Pattern matching with regular expressions
      1. Checking for digits entered as text
      2. Regular expression performance improvements
      3. Understanding the syntax of a regular expression
      4. Examples of regular expressions
      5. Splitting a complex comma-separated string
      6. Activating regular expression syntax coloring
      7. Improving regular expression performance with source generators
    4. Storing multiple objects in collections
      1. Common features of all collections
      2. Improving performance by ensuring the capacity of a collection
      3. Understanding collection choices
        1. Lists
        2. Dictionaries
        3. Stacks
        4. Queues
        5. Sets
        6. Collection methods summary
      4. Working with lists
      5. Working with dictionaries
      6. Working with queues
      7. Sorting collections
      8. More specialized collections
        1. Working with a compact array of bit values
        2. Working with efficient lists
      9. Working with immutable collections
      10. Good practice with collections
    5. Working with spans, indexes, and ranges
      1. Using memory efficiently using spans
      2. Identifying positions with the Index type
      3. Identifying ranges with the Range type
      4. Using indexes, ranges, and spans
    6. Working with network resources
      1. Working with URIs, DNS, and IP addresses
      2. Pinging a server
    7. Practicing and exploring
      1. Exercise 8.1 – Test your knowledge
      2. Exercise 8.2 – Practice regular expressions
      3. Exercise 8.3 – Practice writing extension methods
      4. Exercise 8.4 – Explore topics
    8. Summary
  10. Working with Files, Streams, and Serialization
    1. Managing the filesystem
      1. Handling cross-platform environments and filesystems
      2. Managing drives
      3. Managing directories
      4. Managing files
      5. Managing paths
      6. Getting file information
      7. Controlling how you work with files
    2. Reading and writing with streams
      1. Understanding abstract and concrete streams
        1. Understanding storage streams
        2. Understanding function streams
        3. Understanding stream helpers
      2. Writing to text streams
      3. Writing to XML streams
      4. Simplifying disposal by using the using statement
      5. Compressing streams
      6. Working with tar archives
        1. Reading and writing tar entries
    3. Encoding and decoding text
      1. Encoding strings as byte arrays
      2. Encoding and decoding text in files
    4. Reading and writing with random access handles
    5. Serializing object graphs
      1. Serializing as XML
      2. Generating compact XML
      3. Deserializing XML files
      4. Serializing with JSON
      5. High-performance JSON processing
      6. Controlling JSON processing
      7. New JSON extension methods for working with HTTP responses
      8. Migrating from Newtonsoft to new JSON
    6. Practicing and exploring
      1. Exercise 9.1 – Test your knowledge
      2. Exercise 9.2 – Practice serializing as XML
      3. Exercise 9.3 – Explore topics
    7. Summary
  11. Working with Data Using Entity Framework Core
    1. Understanding modern databases
      1. Understanding legacy Entity Framework
        1. Using the legacy Entity Framework 6.3 or later
      2. Understanding Entity Framework Core
      3. Understanding Database First and Code First
      4. Performance improvements in EF Core 7
      5. Creating a console app for working with EF Core
      6. Using a sample relational database
      7. Using SQLite
        1. Setting up SQLite for Windows
        2. Setting up SQLite for macOS
        3. Setting up SQLite for other OSes
      8. Creating the Northwind sample database for SQLite
        1. If you are using Visual Studio 2022
      9. Managing the Northwind sample database with SQLiteStudio
      10. Using the lightweight ADO.NET provider for SQLite
      11. Using SQL Server for Windows
    2. Setting up EF Core
      1. Choosing an EF Core database provider
      2. Connecting to a database
      3. Defining the Northwind database context class
    3. Defining EF Core models
      1. Using EF Core conventions to define the model
      2. Using EF Core annotation attributes to define the model
      3. Using the EF Core Fluent API to define the model
        1. Understanding data seeding with the Fluent API
      4. Building EF Core models for the Northwind tables
        1. Defining the Category and Product entity classes
      5. Adding tables to the Northwind database context class
      6. Setting up the dotnet-ef tool
      7. Scaffolding models using an existing database
      8. Customizing the reverse engineering templates
      9. Configuring preconvention models
    4. Querying EF Core models
      1. Filtering included entities
      2. Filtering and sorting products
      3. Getting the generated SQL
      4. Logging EF Core
        1. Filtering logs by provider-specific values
        2. Logging with query tags
      5. Pattern matching with Like
      6. Generating a random number in queries
      7. Defining global filters
    5. Loading patterns with EF Core
      1. Eager loading entities using the Include extension method
      2. Enabling lazy loading
      3. Explicit loading entities using the Load method
    6. Modifying data with EF Core
      1. Inserting entities
      2. Updating entities
      3. Deleting entities
      4. More efficient updates and deletes
      5. Pooling database contexts
    7. Working with transactions
      1. Controlling transactions using isolation levels
      2. Defining an explicit transaction
    8. Defining Code First EF Core models
    9. Practicing and exploring
      1. Exercise 10.1 – Test your knowledge
      2. Exercise 10.2 – Practice exporting data using different serialization formats
      3. Exercise 10.3 – Explore topics
      4. Exercise 10.4 – Explore NoSQL databases
    10. Summary
  12. Querying and Manipulating Data Using LINQ
    1. Why LINQ?
      1. Comparing imperative and declarative language features
    2. Writing LINQ expressions
      1. What makes LINQ?
      2. Building LINQ expressions with the Enumerable class
      3. Understanding deferred execution
      4. Filtering entities with Where
      5. Targeting a named method
      6. Simplifying the code by removing the explicit delegate instantiation
      7. Targeting a lambda expression
      8. Sorting entities
        1. Sorting by a single property using OrderBy
        2. Sorting by a subsequent property using ThenBy
      9. Sorting by the item itself
      10. Declaring a query using var or a specified type
      11. Filtering by type
      12. Working with sets and bags using LINQ
    3. Using LINQ with EF Core
      1. Building an EF Core model
        1. Using Visual Studio 2022 with SQLite databases
      2. Filtering and sorting sequences
      3. Projecting sequences into new types
      4. Joining and grouping sequences
        1. Joining sequences
        2. Group-joining sequences
      5. Aggregating sequences
      6. Be careful with Count!
      7. Paging with LINQ
    4. Sweetening LINQ syntax with syntactic sugar
    5. Using multiple threads with parallel LINQ
    6. Creating your own LINQ extension methods
      1. Trying the chainable extension method
        1. Trying the mode and median methods
    7. Working with LINQ to XML
      1. Generating XML using LINQ to XML
      2. Reading XML using LINQ to XML
    8. Practicing and exploring
      1. Exercise 11.1 – Test your knowledge
      2. Exercise 11.2 – Practice querying with LINQ
      3. Exercise 11.3 – Explore topics
    9. Summary
  13. Introducing Web Development Using ASP.NET Core
    1. Understanding ASP.NET Core
      1. Classic ASP.NET versus modern ASP.NET Core
      2. Building websites using ASP.NET Core
        1. Building websites using a content management system
        2. Building web applications using SPA frameworks
      3. Building web and other services
    2. New features in ASP.NET Core
      1. ASP.NET Core 1.0
      2. ASP.NET Core 1.1
      3. ASP.NET Core 2.0
      4. ASP.NET Core 2.1
      5. ASP.NET Core 2.2
      6. ASP.NET Core 3.0
      7. ASP.NET Core 3.1
      8. Blazor WebAssembly 3.2
      9. ASP.NET Core 5.0
      10. ASP.NET Core 6.0
      11. ASP.NET Core 7.0
    3. Structuring projects
      1. Structuring projects in a solution or workspace
    4. Building an entity model for use in the rest of the book
      1. Creating a class library for entity models using SQLite
        1. Improving the class-to-table mapping
        2. Creating a class library for a Northwind database context
      2. Creating a class library for entity models using SQL Server
      3. Testing the class libraries
    5. Understanding web development
      1. Understanding Hypertext Transfer Protocol
        1. Understanding the components of a URL
        2. Assigning port numbers for projects in this book
      2. Using Google Chrome to make HTTP requests
      3. Understanding client-side web development technologies
    6. Practicing and exploring
      1. Exercise 12.1 – Test your knowledge
      2. Exercise 12.2 – Know your webbreviations
      3. Exercise 12.3 – Explore topics
    7. Summary
  14. Building Websites Using ASP.NET Core Razor Pages
    1. Exploring ASP.NET Core
      1. Creating an empty ASP.NET Core project
      2. Testing and securing the website
        1. Enabling stronger security and redirecting to a secure connection
      3. Controlling the hosting environment
      4. Enabling a website to serve static content
        1. Creating a folder for static files and a web page
        2. Enabling static and default files
    2. Exploring ASP.NET Core Razor Pages
      1. Enabling Razor Pages
      2. Adding code to a Razor Page
      3. Using shared layouts with Razor Pages
      4. Using code-behind files with Razor Pages
    3. Using Entity Framework Core with ASP.NET Core
      1. Configuring Entity Framework Core as a service
      2. Manipulating data using Razor Pages
        1. Enabling a model to insert entities
        2. Defining a form to insert a new supplier
      3. Injecting a dependency service into a Razor Page
    4. Using Razor class libraries
      1. Disabling compact folders for Visual Studio Code
      2. Creating a Razor class library
      3. Implementing a partial view to show a single employee
      4. Using and testing a Razor class library
    5. Configuring services and the HTTP request pipeline
      1. Understanding endpoint routing
      2. Configuring endpoint routing
      3. Reviewing the endpoint routing configuration in our project
      4. Setting up the HTTP pipeline
      5. Summarizing key middleware extension methods
      6. Visualizing the HTTP pipeline
      7. Implementing an anonymous inline delegate as middleware
      8. Enabling request decompression support
    6. Enabling HTTP/3 support
    7. Practicing and exploring
      1. Exercise 13.1 – Test your knowledge
      2. Exercise 13.2 – Practice building a data-driven web page
      3. Exercise 13.3 – Practice building web pages for console apps
      4. Exercise 13.4 – Explore topics
    8. Summary
  15. Building Websites Using the Model-View-Controller Pattern
    1. Setting up an ASP.NET Core MVC website
      1. Creating an ASP.NET Core MVC website
      2. Creating the authentication database for SQL Server LocalDB
      3. Exploring the default ASP.NET Core MVC website
      4. Starting the MVC website project
      5. Exploring visitor registration
      6. Reviewing an MVC website project structure
      7. Reviewing the ASP.NET Core Identity database
    2. Exploring an ASP.NET Core MVC website
      1. ASP.NET Core MVC initialization
      2. The default MVC route
      3. Controllers and actions
        1. The ControllerBase class
        2. The Controller class
        3. The responsibilities of a controller
      4. The view search path convention
      5. Logging using the dependency service
      6. Entity and view models
      7. Views
      8. Understanding how cache busting with Tag Helpers works
    3. Customizing an ASP.NET Core MVC website
      1. Defining a custom style
      2. Setting up the category images
      3. Razor syntax and expressions
      4. Defining a typed view
      5. Passing parameters using a route value
      6. Model binders in more detail
        1. Disambiguating action methods
        2. Passing a route parameter
        3. Passing a form parameter
      7. Validating the model
      8. Defining views with HTML Helper methods
      9. Defining views with Tag Helpers
      10. Cross-functional filters
        1. Using a filter to secure an action method
        2. Enabling role management and creating a role programmatically
        3. Using a filter to define a custom route
        4. Using a filter to cache a response
      11. Using output caching
        1. Output caching endpoints
        2. Output caching MVC views
        3. Varying cached data by query string
    4. Querying a database and using display templates
    5. Improving scalability using asynchronous tasks
      1. Making controller action methods asynchronous
    6. Practicing and exploring
      1. Exercise 14.1 – Test your knowledge
      2. Exercise 14.2 – Practice implementing MVC by implementing a category detail page
      3. Exercise 14.3 – Practice improving scalability by understanding and implementing async action methods
      4. Exercise 14.4 – Practice unit testing MVC controllers
      5. Exercise 14.5 – Explore topics
    7. Summary
  16. Building and Consuming Web Services
    1. Building web services using the ASP.NET Core Web API
      1. Understanding web service acronyms
      2. Understanding HTTP requests and responses for Web APIs
      3. Creating an ASP.NET Core Web API project
      4. Reviewing the web service’s functionality
      5. Creating a web service for the Northwind database
      6. Creating data repositories for entities
      7. Implementing a Web API controller
        1. Understanding action method return types
      8. Configuring the customer repository and Web API controller
      9. Specifying problem details
      10. Controlling XML serialization
    2. Documenting and testing web services
      1. Testing GET requests using a browser
      2. Testing HTTP requests with the REST Client extension
        1. Making GET requests using REST Client
        2. Making other requests using REST Client
      3. Understanding Swagger
      4. Testing requests with Swagger UI
      5. Enabling HTTP logging
      6. Support for logging additional request headers in W3CLogger
    3. Consuming web services using HTTP clients
      1. Understanding HttpClient
      2. Configuring HTTP clients using HttpClientFactory
      3. Getting customers as JSON in the controller
      4. Starting multiple projects
        1. If you are using Visual Studio 2022
        2. If you are using Visual Studio Code
      5. Starting the web service and MVC client projects
    4. Implementing advanced features for web services
    5. Building web services using Minimal APIs
      1. Testing the minimal weather service
      2. Adding weather forecasts to the Northwind website home page
    6. Practicing and exploring
      1. Exercise 15.1 – Test your knowledge
      2. Exercise 15.2 – Practice creating and deleting customers with HttpClient
      3. Exercise 15.3 – Explore topics
    7. Summary
  17. Building User Interfaces Using Blazor
    1. Understanding Blazor
      1. JavaScript and friends
      2. Silverlight – C# and .NET using a plugin
      3. WebAssembly – a target for Blazor
      4. Blazor hosting models
      5. Blazor components
      6. What is the difference between Blazor and Razor?
    2. Comparing Blazor project templates
      1. Reviewing the Blazor Server project template
        1. CSS and JavaScript isolation
      2. Blazor routing to page components
        1. How to define a routable page component
        2. How to navigate Blazor routes
        3. How to pass route parameters
        4. Understanding base component classes
        5. How to use the navigation link component with routes
      3. Running the Blazor Server project template
      4. Reviewing the Blazor WebAssembly project template
        1. Deployment choices for Blazor WebAssembly apps
        2. Differences between Blazor Server and Blazor WebAssembly projects
        3. Similarities between Blazor Server and Blazor WebAssembly projects
    3. Building components using Blazor Server
      1. Defining and testing a simple Blazor Server component
      2. Making the component a routable page component
      3. Getting entities into a component
      4. Abstracting a service for a Blazor component
      5. Defining forms using the EditForm component
      6. Building a shared customer detail component
      7. Building customer create, edit, and delete components
      8. Testing the customer components
    4. Building components using Blazor WebAssembly
      1. Configuring the server for Blazor WebAssembly
      2. Configuring the client for Blazor WebAssembly
      3. Testing the Blazor WebAssembly components and service
    5. Improving Blazor WebAssembly apps
    6. Practicing and exploring
      1. Exercise 16.1 – Test your knowledge
      2. Exercise 16.2 – Practice by creating a times table component
      3. Exercise 16.3 – Practice by creating a country navigation item
      4. Exercise 16.4 – Explore topics
    7. Summary
  18. Epilogue
    1. The next steps on your C# and .NET learning journey
      1. Polishing your skills with design guidelines
      2. A companion book to continue your learning journey
      3. Other books to take your learning further
    2. The eighth edition coming November 2023
    3. Good luck!
  19. Index

Product information

  • Title: C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals - Seventh Edition
  • Author(s): Mark J. Price
  • Release date: November 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803237800