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
- Preface
-
Hello, C#! Welcome, .NET!
- Setting up your development environment
-
Understanding .NET
- Understanding .NET Framework
- Understanding the Mono, Xamarin, and Unity projects
- Understanding .NET Core
- Understanding the journey to one .NET
- Understanding .NET support
- What is different about modern .NET?
- Understanding .NET Standard
- .NET platforms and tools used by the C# and .NET book editions
- Topics covered by Apps and Services with .NET 7
- Understanding intermediate language
- Comparing .NET technologies
- Building console apps using Visual Studio 2022
- Building console apps using Visual Studio Code
- Exploring code using .NET Interactive Notebooks
- Reviewing the folders and files for projects
- Making good use of the GitHub repository for this book
-
Looking for help
- Reading Microsoft documentation
- Getting help for the dotnet tool
- Getting definitions of types and their members
- Looking for answers on Stack Overflow
- Searching for answers using Google
- Subscribing to the official .NET blog
- Watching Scott Hanselman’s videos
- A companion book to continue your learning journey
- Practicing and exploring
- Summary
-
Speaking C#
- Introducing the C# language
-
Understanding C# grammar and vocabulary
- Showing the compiler version
- Understanding C# grammar
- Statements
- Comments
- Blocks
- Examples of statements and blocks
- Understanding C# vocabulary
- Comparing programming languages to human languages
- Changing the color scheme for C# syntax
- Help for writing correct code
- Importing namespaces
- Implicitly and globally importing namespaces
- Verbs are methods
- Nouns are types, variables, fields, and properties
- Revealing the extent of the C# vocabulary
- Working with variables
- Exploring more about console apps
- Understanding async and await
- Practicing and exploring
- Summary
-
Controlling Flow, Converting Types, and Handling Exceptions
- Operating on variables
- Understanding selection statements
- Understanding iteration statements
- Storing multiple values in an array
- Casting and converting between types
- Handling exceptions
- Checking for overflow
- Practicing and exploring
- Summary
-
Writing, Debugging, and Testing Functions
- Writing functions
- Debugging during development
- Hot reloading during development
- Logging during development and runtime
- Unit testing
- Throwing and catching exceptions in functions
- Practicing and exploring
- Summary
-
Building Your Own Types with Object-Oriented Programming
- Talking about OOP
- Building class libraries
-
Storing data within fields
- Defining fields
- Understanding access modifiers
- Setting and outputting field values
- Storing a value using an enum type
- Storing multiple values using an enum type
- Storing multiple values using collections
- Understanding generic collections
- Making a field static
- Making a field constant
- Making a field read-only
- Initializing fields with constructors
- Writing and calling methods
- Splitting classes using partial
- Controlling access with properties and indexers
- More about methods
- Pattern matching with objects
- Working with records
- Practicing and exploring
- Summary
-
Implementing Interfaces and Inheriting Classes
- Setting up a class library and console application
- Making types safely reusable with generics
- Raising and handling events
- Implementing interfaces
- Managing memory with reference and value types
- Working with null values
- Inheriting from classes
- Casting within inheritance hierarchies
- Inheriting and extending .NET types
- Writing better code
- Practicing and exploring
- Summary
-
Packaging and Distributing .NET Types
- The road to .NET 7
-
Understanding .NET components
- Assemblies, NuGet packages, and namespaces
- Microsoft .NET project SDKs
- Namespaces and types in assemblies
- NuGet packages
- Understanding frameworks
- Importing a namespace to use a type
- Relating C# keywords to .NET types
- Sharing code with legacy platforms using .NET Standard
- Understanding defaults for class libraries with different SDKs
- Creating a .NET Standard 2.0 class library
- Controlling the .NET SDK
- Publishing your code for deployment
- Decompiling .NET assemblies
- Packaging your libraries for NuGet distribution
- Porting from .NET Framework to modern .NET
- Working with preview features
- Practicing and exploring
- Summary
-
Working with Common .NET Types
- Working with numbers
- Working with text
-
Pattern matching with regular expressions
- Checking for digits entered as text
- Regular expression performance improvements
- Understanding the syntax of a regular expression
- Examples of regular expressions
- Splitting a complex comma-separated string
- Activating regular expression syntax coloring
- Improving regular expression performance with source generators
-
Storing multiple objects in collections
- Common features of all collections
- Improving performance by ensuring the capacity of a collection
- Understanding collection choices
- Working with lists
- Working with dictionaries
- Working with queues
- Sorting collections
- More specialized collections
- Working with immutable collections
- Good practice with collections
- Working with spans, indexes, and ranges
- Working with network resources
- Practicing and exploring
- Summary
-
Working with Files, Streams, and Serialization
- Managing the filesystem
- Reading and writing with streams
- Encoding and decoding text
- Reading and writing with random access handles
- Serializing object graphs
- Practicing and exploring
- Summary
-
Working with Data Using Entity Framework Core
-
Understanding modern databases
- Understanding legacy Entity Framework
- Understanding Entity Framework Core
- Understanding Database First and Code First
- Performance improvements in EF Core 7
- Creating a console app for working with EF Core
- Using a sample relational database
- Using SQLite
- Creating the Northwind sample database for SQLite
- Managing the Northwind sample database with SQLiteStudio
- Using the lightweight ADO.NET provider for SQLite
- Using SQL Server for Windows
- Setting up EF Core
-
Defining EF Core models
- Using EF Core conventions to define the model
- Using EF Core annotation attributes to define the model
- Using the EF Core Fluent API to define the model
- Building EF Core models for the Northwind tables
- Adding tables to the Northwind database context class
- Setting up the dotnet-ef tool
- Scaffolding models using an existing database
- Customizing the reverse engineering templates
- Configuring preconvention models
- Querying EF Core models
- Loading patterns with EF Core
- Modifying data with EF Core
- Working with transactions
- Defining Code First EF Core models
- Practicing and exploring
- Summary
-
Understanding modern databases
-
Querying and Manipulating Data Using LINQ
- Why LINQ?
-
Writing LINQ expressions
- What makes LINQ?
- Building LINQ expressions with the Enumerable class
- Understanding deferred execution
- Filtering entities with Where
- Targeting a named method
- Simplifying the code by removing the explicit delegate instantiation
- Targeting a lambda expression
- Sorting entities
- Sorting by the item itself
- Declaring a query using var or a specified type
- Filtering by type
- Working with sets and bags using LINQ
- Using LINQ with EF Core
- Sweetening LINQ syntax with syntactic sugar
- Using multiple threads with parallel LINQ
- Creating your own LINQ extension methods
- Working with LINQ to XML
- Practicing and exploring
- Summary
- Introducing Web Development Using ASP.NET Core
-
Building Websites Using ASP.NET Core Razor Pages
- Exploring ASP.NET Core
- Exploring ASP.NET Core Razor Pages
- Using Entity Framework Core with ASP.NET Core
- Using Razor class libraries
-
Configuring services and the HTTP request pipeline
- Understanding endpoint routing
- Configuring endpoint routing
- Reviewing the endpoint routing configuration in our project
- Setting up the HTTP pipeline
- Summarizing key middleware extension methods
- Visualizing the HTTP pipeline
- Implementing an anonymous inline delegate as middleware
- Enabling request decompression support
- Enabling HTTP/3 support
- Practicing and exploring
- Summary
-
Building Websites Using the Model-View-Controller Pattern
- Setting up an ASP.NET Core MVC website
- Exploring an ASP.NET Core MVC website
-
Customizing an ASP.NET Core MVC website
- Defining a custom style
- Setting up the category images
- Razor syntax and expressions
- Defining a typed view
- Passing parameters using a route value
- Model binders in more detail
- Validating the model
- Defining views with HTML Helper methods
- Defining views with Tag Helpers
- Cross-functional filters
- Using output caching
- Querying a database and using display templates
- Improving scalability using asynchronous tasks
-
Practicing and exploring
- Exercise 14.1 – Test your knowledge
- Exercise 14.2 – Practice implementing MVC by implementing a category detail page
- Exercise 14.3 – Practice improving scalability by understanding and implementing async action methods
- Exercise 14.4 – Practice unit testing MVC controllers
- Exercise 14.5 – Explore topics
- Summary
-
Building and Consuming Web Services
-
Building web services using the ASP.NET Core Web API
- Understanding web service acronyms
- Understanding HTTP requests and responses for Web APIs
- Creating an ASP.NET Core Web API project
- Reviewing the web service’s functionality
- Creating a web service for the Northwind database
- Creating data repositories for entities
- Implementing a Web API controller
- Configuring the customer repository and Web API controller
- Specifying problem details
- Controlling XML serialization
- Documenting and testing web services
- Consuming web services using HTTP clients
- Implementing advanced features for web services
- Building web services using Minimal APIs
- Practicing and exploring
- Summary
-
Building web services using the ASP.NET Core Web API
-
Building User Interfaces Using Blazor
- Understanding Blazor
- Comparing Blazor project templates
-
Building components using Blazor Server
- Defining and testing a simple Blazor Server component
- Making the component a routable page component
- Getting entities into a component
- Abstracting a service for a Blazor component
- Defining forms using the EditForm component
- Building a shared customer detail component
- Building customer create, edit, and delete components
- Testing the customer components
- Building components using Blazor WebAssembly
- Improving Blazor WebAssembly apps
- Practicing and exploring
- Summary
- Epilogue
- Index
Product information
- Title: C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals - Seventh Edition
- Author(s):
- Release date: November 2022
- Publisher(s): Packt Publishing
- ISBN: 9781803237800
You might also like
book
C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition
Publisher’s Note: Microsoft will stop supporting .NET 6 from November 2024. The newer 8th edition of …
book
C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals - Eighth Edition
An accessible guide for beginner-to-intermediate programmers to the concepts, real-world applications, and latest features of C# …
book
C# 9 and .NET 5 – Modern Cross-Platform Development - Fifth Edition
Publisher’s Note: Microsoft stopped supporting .NET 5 in May 2022. The newer 8th edition of the …
video
C# Basics For Absolute Beginners in C# and .NET
Do you want to understand C# development environments and C# coding concepts such as variables, operators, …