C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition

Book description

Publisher’s Note: Microsoft will stop supporting .NET 6 from November 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 8. Purchase of the print or Kindle book includes a free PDF eBook

Key Features

  • Explore the newest additions to C# 10, the .NET 6 class library, and Entity Framework Core 6
  • Create professional websites and services with ASP.NET Core 6 and Blazor
  • Build cross-platform apps for Windows, macOS, Linux, iOS, and Android

Book Description

Extensively revised to accommodate all the latest features that come with C# 10 and .NET 6, this latest edition of our comprehensive 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. The book covers the .NET APIs for performing tasks like managing and querying data, monitoring and improving performance, and working with the filesystem, async streams, and serialization. You’ll build and deploy cross-platform apps, such as websites and services using ASP.NET Core.

Instead of distracting you with unnecessary application code, the first twelve chapters will teach you about C# language constructs and many of the .NET libraries through simple console applications. In later chapters, having mastered the basics, you’ll then build practical applications and services using ASP.NET Core, the Model-View-Controller (MVC) pattern, and Blazor.

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
  • Build your own types with object-oriented programming
  • Write, test, and debug functions
  • Query and manipulate data using LINQ
  • Integrate and update databases in your apps using Entity Framework Core, Microsoft SQL Server, and SQLite
  • Build and consume powerful services using the latest technologies, including gRPC and GraphQL
  • Build cross-platform apps using XAML

Who this book is for

Designed for both beginners and 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, this book doesn’t need you to have any C# or .NET experience. However, you should have a general understanding of programming before you jump in.

Table of contents

  1. Preface
    1. Where to find the code solutions
    2. Where to find the online chapters
    3. What this book covers
    4. What you need for this book
    5. Get in touch
    6. Share your thoughts
  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. Understanding Microsoft Visual Studio Code versions
        3. 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
      5. Understanding .NET support
        1. Understanding .NET Runtime and .NET SDK versions
        2. Removing old versions of .NET
      6. What is different about modern .NET?
        1. Windows development
        2. Web development
        3. Database development
      7. Themes of modern .NET
      8. Understanding .NET Standard
      9. .NET platforms and tools used by the book editions
      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. Writing top-level programs
      5. Adding a second project using Visual Studio 2022
        1. Implicitly imported namespaces
    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. Managing multiple files using Visual Studio Code
    5. Exploring code using .NET Interactive Notebooks
      1. Creating a notebook
      2. Writing and running code in a notebook
      3. Saving a notebook
      4. Adding Markdown and special commands to a notebook
      5. Executing code in multiple cells
      6. 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
    9. Practicing and exploring
      1. Exercise 1.1 – Test your knowledge
      2. Exercise 1.2 – Practice C# anywhere
      3. Exercise 1.3 – Explore topics
    10. Summary
  3. Speaking C#
    1. Introducing the C# language
      1. Understanding language versions and features
        1. C# 1.0
        2. C# 2.0
        3. C# 3.0
        4. C# 4.0
        5. C# 5.0
        6. C# 6.0
        7. C# 7.0
        8. C# 7.1
        9. C# 7.2
        10. C# 7.3
        11. C# 8
        12. C# 9
        13. C# 10
      2. Understanding C# standards
      3. Discovering your C# compiler versions
        1. How to output the SDK version
        2. Enabling a specific language version compiler
    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
        1. Implicitly and globally importing namespaces
      12. Verbs are methods
      13. Nouns are types, variables, fields, and properties
      14. Revealing the extent of the C# vocabulary
    3. Working with variables
      1. Naming things and assigning values
      2. Literal values
      3. Storing text
        1. Understanding verbatim strings
      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
      11. Storing multiple values in an array
    4. Exploring more about console applications
      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
      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. 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
    6. 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. 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
    5. Handling exceptions
      1. Wrapping error-prone code in a try block
        1. Catching all exceptions
        2. Catching specific exceptions
        3. Catching with filters
    6. Checking for overflow
      1. Throwing overflow exceptions with the checked statement
      2. Disabling compiler overflow checks with the unchecked statement
    7. 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
    8. Summary
  5. Writing, Debugging, and Testing Functions
    1. Writing functions
      1. Times table example
        1. Writing a times table function
      2. Writing a function that returns a value
      3. Converting numbers from cardinal to ordinal
      4. Calculating factorials with recursion
      5. Documenting functions with XML comments
      6. Using lambdas in function implementations
    2. Debugging during development
      1. Creating code with a deliberate bug
      2. Setting a breakpoint and start debugging
        1. Using Visual Studio 2022
        2. Using Visual Studio Code
      3. Navigating with the debugging toolbar
      4. Debugging windows
      5. Stepping through code
      6. Customizing breakpoints
    3. 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 Code
        2. Adding packages to a project in Visual Studio 2022
        3. Reviewing project packages
    4. 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 Code
        2. Running unit tests using Visual Studio
        3. Fix the bug
    5. 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
    6. 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
    7. 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
        1. Simplifying namespace declarations
      3. Understanding members
      4. Instantiating a class
        1. Referencing an assembly
      5. Importing a namespace to use a type
      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
    4. Storing multiple values using collections
      1. Understanding generic collections
      2. Making a field static
      3. Making a field constant
      4. Making a field read-only
      5. Initializing fields with constructors
        1. Defining multiple constructors
    5. Writing and calling methods
      1. Returning values from methods
      2. Combining multiple returned values using tuples
        1. Language support for tuples
        2. Naming the fields of a tuple
        3. Inferring tuple names
        4. Deconstructing tuples
        5. 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
      8. 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. Pattern matching with objects
      1. Creating and referencing a .NET 6 class library
      2. Defining flight passengers
      3. Enhancements to pattern matching in C# 9 or later
    8. Working with records
      1. Init-only properties
      2. Understanding records
      3. Positional data members in records
        1. Simplifying data members in records
    9. Practicing and exploring
      1. Exercise 5.1 – Test your knowledge
      2. Exercise 5.2 – Explore topics
    10. Summary
  7. Implementing Interfaces and Inheriting Classes
    1. Setting up a class library and console application
    2. More about methods
      1. Implementing functionality using methods
      2. Implementing functionality using operators
      3. Implementing functionality using local functions
    3. Raising and handling events
      1. Calling methods using delegates
      2. Defining and handling delegates
      3. Defining and handling events
    4. Making types safely reusable with generics
      1. Working with non-generic types
      2. Working with generic types
    5. 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
    6. 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. Working with record struct types
      6. Releasing unmanaged resources
      7. Ensuring that Dispose is called
    7. Working with null values
      1. Making a value type nullable
      2. Understanding nullable reference types
      3. Enabling nullable and non-nullable reference types
      4. Declaring non-nullable variables and parameters
      5. Checking for null
        1. Checking for null in method parameters
    8. 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
    9. Casting within inheritance hierarchies
      1. Implicit casting
      2. Explicit casting
      3. Avoiding casting exceptions
    10. 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
    11. Using an analyzer to write better code
      1. Suppressing warnings
        1. Fixing the code
        2. Understanding common StyleCop recommendations
    12. 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
    13. Summary
  8. Packaging and Distributing .NET Types
    1. The road to .NET 6
      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. Improving performance from .NET Core 2.0 to .NET 5
      11. Checking your .NET SDKs for updates
    2. Understanding .NET components
      1. Understanding assemblies, NuGet packages, and namespaces
        1. What is a namespace?
        2. Understanding dependent assemblies
      2. Understanding the Microsoft .NET project SDKs
      3. Understanding namespaces and types in assemblies
      4. Understanding 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. 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 application 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. Decompiling using the ILSpy extension for Visual Studio Code
      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. Understanding the .NET Portability Analyzer
      5. Understanding the .NET Upgrade Assistant
      6. Using non-.NET Standard libraries
    7. Working with preview features
      1. Requiring preview features
      2. Enabling preview features
      3. Generic mathematics
    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
    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. Working with dates and times
      1. Specifying date and time values
      2. Globalization with dates and times
      3. Working with only a date or a time
    4. 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
    5. 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. Using immutable collections
      10. Good practice with collections
    6. 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
    7. Working with network resources
      1. Working with URIs, DNS, and IP addresses
      2. Pinging a server
    8. Working with reflection and attributes
      1. Versioning of assemblies
      2. Reading assembly metadata
      3. Creating custom attributes
      4. Doing more with reflection
    9. Working with images
    10. Internationalizing your code
      1. Detecting and changing the current culture
    11. 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
    12. 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. Disposing of file resources
        1. Simplifying disposal by using the using statement
      5. Compressing streams
      6. Compressing with the Brotli algorithm
    3. Encoding and decoding text
      1. Encoding strings as byte arrays
      2. Encoding and decoding text in files
    4. Serializing object graphs
      1. Serializing as XML
      2. Generating compact XML
      3. Deserializing XML files
      4. Serializing with JSON
      5. High-performance JSON processing
    5. Controlling JSON processing
      1. New JSON extension methods for working with HTTP responses
      2. 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. Creating a console app for working with EF Core
      4. Using a sample relational database
      5. Using Microsoft SQL Server for Windows
        1. Downloading and installing SQL Server
      6. Creating the Northwind sample database for SQL Server
      7. Managing the Northwind sample database with Server Explorer
      8. Using SQLite
        1. Setting up SQLite for macOS
        2. Setting up SQLite for Windows
        3. Setting up SQLite for other OSes
      9. Creating the Northwind sample database for SQLite
      10. Managing the Northwind sample database with SQLiteStudio
    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 an EF Core model 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. Configuring preconvention models
    4. Querying EF Core models
      1. Filtering included entities
        1. Unicode characters in the Windows console
      2. Filtering and sorting products
      3. Getting the generated SQL
      4. Logging EF Core using a custom logging provider
        1. Filtering logs by provider-specific values
        2. Logging with query tags
      5. Pattern matching with Like
      6. Defining global filters
    5. Loading patterns with EF Core
      1. Eager loading entities
      2. Enabling lazy loading
      3. Explicit loading entities
    6. Manipulating data with EF Core
      1. Inserting entities
      2. Updating entities
      3. Deleting entities
      4. Pooling database contexts
    7. Working with transactions
      1. Controlling transactions using isolation levels
      2. Defining an explicit transaction
    8. Code First EF Core models
      1. Understanding migrations
    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. Writing LINQ expressions
      1. What makes LINQ?
      2. Building LINQ expressions with the Enumerable class
        1. Understanding deferred execution
      3. Filtering entities with Where
      4. Targeting a named method
      5. Simplifying the code by removing the explicit delegate instantiation
      6. Targeting a lambda expression
      7. Sorting entities
        1. Sorting by a single property using OrderBy
        2. Sorting by a subsequent property using ThenBy
      8. Declaring a query using var or a specified type
      9. Filtering by type
      10. Working with sets and bags using LINQ
    2. Using LINQ with EF Core
      1. Building an EF Core model
      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
    3. Sweetening LINQ syntax with syntactic sugar
    4. Using multiple threads with parallel LINQ
      1. Creating an app that benefits from multiple threads
        1. Using Windows
        2. Using macOS
        3. For all operating systems
    5. Creating your own LINQ extension methods
      1. Trying the chainable extension method
        1. Trying the mode and median methods
    6. Working with LINQ to XML
      1. Generating XML using LINQ to XML
      2. Reading XML using LINQ to XML
    7. Practicing and exploring
      1. Exercise 11.1 – Test your knowledge
      2. Exercise 11.2 – Practice querying with LINQ
      3. Exercise 11.3 – Explore topics
    8. Summary
  13. Improving Performance and Scalability Using Multitasking
    1. Understanding processes, threads, and tasks
    2. Monitoring performance and resource usage
      1. Evaluating the efficiency of types
      2. Monitoring performance and memory using diagnostics
        1. Useful members of the Stopwatch and Process types
        2. Implementing a Recorder class
      3. Measuring the efficiency of processing strings
      4. Monitoring performance and memory using Benchmark.NET
    3. Running tasks asynchronously
      1. Running multiple actions synchronously
      2. Running multiple actions asynchronously using tasks
        1. Starting tasks
      3. Waiting for tasks
        1. Using wait methods with tasks
      4. Continuing with another task
      5. Nested and child tasks
      6. Wrapping tasks around other objects
    4. Synchronizing access to shared resources
      1. Accessing a resource from multiple threads
      2. Applying a mutually exclusive lock to a conch
        1. Understanding the lock statement
        2. Avoiding deadlocks
      3. Synchronizing events
      4. Making CPU operations atomic
      5. Applying other types of synchronization
    5. Understanding async and await
      1. Improving responsiveness for console apps
      2. Improving responsiveness for GUI apps
      3. Improving scalability for web applications and web services
      4. Common types that support multitasking
      5. Using await in catch blocks
      6. Working with async streams
    6. Practicing and exploring
      1. Exercise 12.1 – Test your knowledge
      2. Exercise 12.2 – Explore topics
    7. Summary
  14. Introducing Practical Applications of C# and .NET
    1. Understanding app models for C# and .NET
      1. Building websites using ASP.NET Core
        1. Building websites using a content management system
        2. Building web applications using SPA frameworks
      2. Building web and other services
      3. Building mobile and desktop apps
      4. Alternatives to .NET MAUI
        1. Understanding Uno Platform
        2. Understanding Avalonia
    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
    3. Building Windows-only desktop apps
      1. Understanding legacy Windows application platforms
      2. Understanding modern .NET support for legacy Windows platforms
    4. Structuring projects
      1. Structuring projects in a solution or workspace
    5. Using other project templates
      1. Installing additional template packs
    6. Building an entity data model for the Northwind database
      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
    7. Practicing and exploring
      1. Exercise 13.1 – Test your knowledge
      2. Exercise 13.2 – Explore topics
    8. Summary
  15. Building Websites Using ASP.NET Core Razor Pages
    1. Understanding web development
      1. Understanding HTTP
        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
    2. Understanding ASP.NET Core
      1. Classic ASP.NET versus modern ASP.NET Core
      2. Creating an empty ASP.NET Core project
      3. Testing and securing the website
        1. Enabling stronger security and redirect to a secure connection
      4. Controlling the hosting environment
      5. Separating configuration for services and pipeline
      6. Enabling a website to serve static content
        1. Creating a folder for static files and a web page
        2. Enabling static and default files
    3. 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
    4. Using Entity Framework Core with ASP.NET Core
      1. Configure 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
    5. Using Razor class libraries
      1. Creating a Razor class library
      2. Disabling compact folders for Visual Studio Code
      3. Implementing the employees feature using EF Core
      4. Implementing a partial view to show a single employee
      5. Using and testing a Razor class library
    6. Configuring services and the HTTP request pipeline
      1. Understanding endpoint routing
        1. Configuring endpoint routing
      2. Reviewing the endpoint routing configuration in our project
        1. Registering services in the ConfigureServices method
        2. Setting up the HTTP request pipeline in the Configure method
      3. Summarizing key middleware extension methods
      4. Visualizing the HTTP pipeline
      5. Implementing an anonymous inline delegate as middleware
    7. Practicing and exploring
      1. Exercise 14.1 – Test your knowledge
      2. Exercise 14.2 – Practice building a data-driven web page
      3. Exercise 14.3 – Practice building web pages for console apps
      4. Exercise 14.4 – Explore topics
    8. Summary
  16. 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
        1. Understanding visitor registration
      4. Reviewing an MVC website project structure
      5. Reviewing the ASP.NET Core Identity database
    2. Exploring an ASP.NET Core MVC website
      1. Understanding ASP.NET Core MVC initialization
      2. Understanding the default MVC route
      3. Understanding controllers and actions
        1. Understanding the ControllerBase class
        2. Understanding the Controller class
        3. Understanding the responsibilities of a controller
      4. Understanding the view search path convention
      5. Understanding logging
      6. Understanding filters
        1. Using a filter to secure an action method
        2. Enabling role management and creating a role programmatically
        3. Using a filter to cache a response
        4. Using a filter to define a custom route
      7. Understanding entity and view models
      8. Understanding views
    3. Customizing an ASP.NET Core MVC website
      1. Defining a custom style
      2. Setting up the category images
      3. Understanding Razor syntax
      4. Defining a typed view
      5. Reviewing the customized home page
      6. Passing parameters using a route value
      7. Understanding model binders in more detail
        1. Disambiguating action methods
        2. Passing a route parameter
        3. Passing a form parameter
      8. Validating the model
      9. Understanding view helper methods
    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 15.1 – Test your knowledge
      2. Exercise 15.2 – Practice implementing MVC by implementing a category detail page
      3. Exercise 15.3 – Practice improving scalability by understanding and implementing async action methods
      4. Exercise 15.4 – Practice unit testing MVC controllers
      5. Exercise 15.5 – Explore topics
    7. Summary
  17. Building and Consuming Web Services
    1. Building web services using ASP.NET Core Web API
      1. Understanding web service acronyms
        1. Understanding Windows Communication Foundation (WCF)
        2. An alternative to WCF
      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
    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. Enabling Cross-Origin Resource Sharing
    4. Implementing advanced features for web services
      1. Implementing a Health Check API
      2. Implementing Open API analyzers and conventions
      3. Implementing transient fault handling
      4. Adding security HTTP headers
    5. Building web services using minimal APIs
      1. Building a weather service using minimal APIs
      2. Testing the minimal weather service
      3. Adding weather forecasts to the Northwind website home page
    6. Practicing and exploring
      1. Exercise 16.1 – Test your knowledge
      2. Exercise 16.2 – Practice creating and deleting customers with HttpClient
      3. Exercise 16.3 – Explore topics
    7. Summary
  18. 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. Understanding Blazor hosting models
      5. Understanding Blazor components
      6. What is the difference between Blazor and Razor?
    2. Comparing Blazor project templates
      1. Reviewing the Blazor Server project template
        1. Understanding CSS and JavaScript isolation
      2. Understanding 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
    3. Building components using Blazor Server
      1. Defining and testing a simple component
      2. Making the component a routable page component
      3. Getting entities into a component
    4. Abstracting a service for a Blazor component
      1. Defining forms using the EditForm component
      2. Building and using a customer form component
      3. Testing the customer form component
    5. 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
    6. Improving Blazor WebAssembly apps
      1. Enabling Blazor WebAssembly AOT
      2. Exploring Progressive Web App support
        1. Implementing offline support for PWAs
      3. Understanding the browser compatibility analyzer for Blazor WebAssembly
      4. Sharing Blazor components in a class library
      5. Interop with JavaScript
      6. Libraries of Blazor components
    7. Practicing and exploring
      1. Exercise 17.1 – Test your knowledge
      2. Exercise 17.2 – Practice by creating a times table component
      3. Exercise 17.3 – Practice by creating a country navigation item
      4. Exercise 17.4 – Explore topics
    8. Summary
  19. Epilogue
    1. Next steps on your C# and .NET learning journey
      1. Polishing your skills with design guidelines
      2. Books to take your learning further
    2. .NET MAUI delayed
    3. Next edition coming November 2022
    4. Good luck!
    5. Share your thoughts
  20. Index

Product information

  • Title: C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition
  • Author(s): Mark J. Price
  • Release date: November 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781801077361