Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Preface
What this book covers
What you need for this book
Downloading the color images of this book
Conventions
Get in touch
Reviews
Hello, C#! Welcome, .NET!
Setting up your development environment
Using Visual Studio Code for cross-platform development
Using GitHub Codespaces for development in the cloud
Using Visual Studio 2019 for Windows app development
Using Visual Studio for Mac for mobile development
Recommended tools for chapters
Deploying cross-platform
Understanding Microsoft Visual Studio Code versions
Downloading and installing Visual Studio Code
Installing other extensions
Understanding .NET
Understanding .NET Framework
Understanding the Mono and Xamarin projects
Understanding .NET Core
Understanding .NET 5 and the journey to one .NET
Understanding .NET support
Understanding .NET Runtime and .NET SDK versions
Removing old versions of .NET
What is different about .NET Core and .NET 5?
Understanding .NET Standard
.NET platforms and tools used by the book editions
Understanding intermediate language
Comparing .NET technologies
Building console apps using Visual Studio Code
Writing code using Visual Studio Code
Compiling and running code using the dotnet CLI
Writing top-level programs
Downloading solution code from the GitHub repository
Using Git with Visual Studio Code
Cloning the book solution code repository
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
Scott Hanselman's videos
Practicing and exploring
Exercise 1.1 – Test your knowledge
Exercise 1.2 – Practice C# anywhere
Exercise 1.3 – Explore topics
Summary
Speaking C#
Introducing C#
Understanding language versions and features
C# 1.0
C# 2.0
C# 3.0
C# 4.0
C# 5.0
C# 6.0
C# 7.0
C# 7.1
C# 7.2
C# 7.3
C# 8.0
C# 9.0
Discovering your C# compiler versions
Enabling a specific language version compiler
Understanding C# basics
Understanding C# grammar
Statements
Comments
Blocks
Understanding C# vocabulary
Changing the color scheme for syntax
Comparing programming languages to human languages
Help for writing correct code
Verbs are methods
Nouns are types, fields, and variables
Revealing the extent of the C# vocabulary
Working with variables
Naming things and assigning values
Literal values
Storing text
Understanding verbatim strings
Storing numbers
Storing whole numbers
Storing real numbers
Writing code to explore number sizes
Comparing double and decimal types
Storing Booleans
Using Visual Studio Code workspaces
Storing any type of object
Storing dynamic types
Declaring local variables
Specifying and inferring the type of a local variable
Using target-typed new to instantiate objects
Getting default values for types
Storing multiple values
Working with null values
Making a value type nullable
Understanding nullable reference types
Enabling nullable and non-nullable reference types
Declaring non-nullable variables and parameters
Checking for null
Exploring console applications further
Displaying output to the user
Formatting using numbered positional arguments
Formatting using interpolated strings
Understanding format strings
Getting text input from the user
Importing a namespace
Simplifying the usage of the console
Getting key input from the user
Getting arguments
Setting options with arguments
Handling platforms that do not support an API
Practicing and exploring
Exercise 2.1 – Test your knowledge
Exercise 2.2 – Practice number sizes and ranges
Exercise 2.3 – Explore topics
Summary
Controlling Flow and Converting Types
Operating on variables
Unary operators
Binary arithmetic operators
Assignment operators
Logical operators
Conditional logical operators
Bitwise and binary shift operators
Miscellaneous operators
Understanding selection statements
Branching with the if statement
Why you should always use braces with if statements
Pattern matching with the if statement
Branching with the switch statement
Pattern matching with the switch statement
Simplifying switch statements with switch expressions
Understanding iteration statements
Looping with the while statement
Looping with the do statement
Looping with the for statement
Looping with the foreach statement
Understanding how foreach works internally
Casting and converting between types
Casting numbers implicitly and explicitly
Converting with the System.Convert type
Rounding numbers
Understanding the default rounding rules
Taking control of rounding rules
Converting from any type to a string
Converting from a binary object to a string
Parsing from strings to numbers or dates and times
Avoiding exceptions using the TryParse method
Handling exceptions when converting types
Wrapping error-prone code in a try block
Catching all exceptions
Catching specific exceptions
Checking for overflow
Throwing overflow exceptions with the checked statement
Disabling compiler overflow checks with the unchecked statement
Practicing and exploring
Exercise 3.1 – Test your knowledge
Exercise 3.2 – Explore loops and overflow
Exercise 3.3 – Practice loops and operators
Exercise 3.4 – Practice exception handling
Exercise 3.5 – Test your knowledge of operators
Exercise 3.6 – Explore topics
Summary
Writing, Debugging, and Testing Functions
Writing functions
Writing a times table function
Writing a function that returns a value
Writing mathematical functions
Converting numbers from cardinal to ordinal
Calculating factorials with recursion
Documenting functions with XML comments
Using lambdas in function implementations
Debugging during development
Creating code with a deliberate bug
Setting a breakpoint
Navigating with the debugging toolbar
Debugging windows
Stepping through code
Customizing breakpoints
Logging during development and runtime
Instrumenting with Debug and Trace
Writing to the default trace listener
Configuring trace listeners
Switching trace levels
Unit testing functions
Creating a class library that needs testing
Writing unit tests
Running unit tests
Practicing and exploring
Exercise 4.1 – Test your knowledge
Exercise 4.2 – Practice writing functions with debugging and unit testing
Exercise 4.3 – Explore topics
Summary
Building Your Own Types with Object-Oriented Programming
Talking about object-oriented programming
Building class libraries
Creating a class library
Defining a class
Understanding members
Instantiating a class
Referencing an assembly
Importing a namespace to use a type
Managing multiple files
Understanding objects
Inheriting from System.Object
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
Making a field static
Making a field constant
Making a field read-only
Initializing fields with constructors
Setting fields with default literals
Writing and calling methods
Returning values from methods
Combining multiple returned values using tuples
Naming the fields of a tuple
Inferring tuple names
Deconstructing tuples
Defining and passing parameters to methods
Overloading methods
Passing optional parameters and naming arguments
Controlling how parameters are passed
Understanding ref returns
Splitting classes using partial
Controlling access with properties and indexers
Defining read-only properties
Defining settable properties
Defining indexers
Pattern matching with objects
Creating and referencing a .NET 5 class library
Defining flight passengers
Enhancements to pattern matching in C# 9
Working with records
Init-only properties
Understanding records
Simplifying data members
Positional records
Practicing and exploring
Exercise 5.1 – Test your knowledge
Exercise 5.2 – Explore topics
Summary
Implementing Interfaces and Inheriting Classes
Setting up a class library and console application
Simplifying methods
Implementing functionality using methods
Implementing functionality using operators
Implementing functionality using local functions
Raising and handling events
Calling methods using delegates
Defining and handling delegates
Defining and handling events
Implementing interfaces
Common interfaces
Comparing objects when sorting
Comparing objects using a separate class
Defining interfaces with default implementations
Making types safely reusable with generics
Working with generic types
Working with generic methods
Managing memory with reference and value types
Working with struct types
Releasing unmanaged resources
Ensuring that Dispose is called
Inheriting from classes
Extending classes to add functionality
Hiding members
Overriding members
Preventing inheritance and overriding
Understanding polymorphism
Casting within inheritance hierarchies
Implicit casting
Explicit casting
Avoiding casting exceptions
Inheriting and extending .NET types
Inheriting exceptions
Extending types when you can't inherit
Using static methods to reuse functionality
Using extension methods to reuse functionality
Practicing and exploring
Exercise 6.1 – Test your knowledge
Exercise 6.2 – Practice creating an inheritance hierarchy
Exercise 6.3 – Explore topics
Summary
Understanding and Packaging .NET Types
Introducing .NET 5
.NET Core 1.0
.NET Core 1.1
.NET Core 2.0
.NET Core 2.1
.NET Core 2.2
.NET Core 3.0
.NET 5.0
Improving performance from .NET Core 2.0 to .NET 5
Understanding .NET components
Understanding assemblies, packages, and namespaces
Understanding dependent assemblies
Understanding the Microsoft .NET project SDKs
Understanding 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
Creating a .NET Standard 2.0 class library
Publishing your applications for deployment
Creating a console application to publish
Understanding dotnet commands
Creating new projects
Managing projects
Publishing a self-contained app
Publishing a single-file app
Reducing the size of apps using app trimming
Decompiling assemblies
Packaging your libraries for NuGet distribution
Referencing a NuGet package
Fixing dependencies
Packaging a library for NuGet
Testing your package
Porting from .NET Framework to .NET 5
Could you port?
Should you port?
Differences between .NET Framework and .NET 5
Understanding the .NET Portability Analyzer
Using non-.NET Standard libraries
Practicing and exploring
Exercise 7.1 – Test your knowledge
Exercise 7.2 – Explore topics
Summary
Working with Common .NET Types
Working with numbers
Working with big integers
Working with complex numbers
Working with text
Getting the length of a string
Getting the characters of a string
Splitting a string
Getting part of a string
Checking a string for content
Joining, formatting, and other string members
Building strings efficiently
Pattern matching with regular expressions
Checking for digits entered as text
Understanding the syntax of a regular expression
Examples of regular expressions
Splitting a complex comma-separated string
Regular expression performance improvements
Storing multiple objects in collections
Common features of all collections
Understanding collection choices
Lists
Dictionaries
Stacks
Queues
Sets
Working with lists
Working with dictionaries
Sorting collections
Using specialized collections
Using immutable collections
Working with spans, indexes, and ranges
Using memory efficiently using spans
Identifying positions with the Index type
Identifying ranges with the Range type
Using indexes and ranges
Working with network resources
Working with URIs, DNS, and IP addresses
Pinging a server
Working with types and attributes
Versioning of assemblies
Reading assembly metadata
Creating custom attributes
Doing more with reflection
Working with images
Internationalizing your code
Detecting and changing the current culture
Handling time zones
Practicing and exploring
Exercise 8.1 – Test your knowledge
Exercise 8.2 – Practice regular expressions
Exercise 8.3 – Practice writing extension methods
Exercise 8.4 – Explore topics
Summary
Working with Files, Streams, and Serialization
Managing the filesystem
Handling cross-platform environments and filesystems
Managing drives
Managing directories
Managing files
Managing paths
Getting file information
Controlling how you work with files
Reading and writing with streams
Writing to text streams
Writing to XML streams
Disposing of file resources
Compressing streams
Compressing with the Brotli algorithm
High-performance streams using pipelines
Asynchronous streams
Encoding and decoding text
Encoding strings as byte arrays
Encoding and decoding text in files
Serializing object graphs
Serializing as XML
Generating compact XML
Deserializing XML files
Serializing with JSON
High-performance JSON processing
Practicing and exploring
Exercise 9.1 – Test your knowledge
Exercise 9.2 – Practice serializing as XML
Exercise 9.3 – Explore topics
Summary
Protecting Your Data and Applications
Understanding the vocabulary of protection
Keys and key sizes
IVs and block sizes
Salts
Generating keys and IVs
Encrypting and decrypting data
Encrypting symmetrically with AES
Hashing data
Hashing with the commonly used SHA256
Signing data
Signing with SHA256 and RSA
Generating random numbers
Generating random numbers for games
Generating random numbers for cryptography
What's new in cryptography?
Authenticating and authorizing users
Implementing authentication and authorization
Protecting application functionality
Practicing and exploring
Exercise 10.1 – Test your knowledge
Exercise 10.2 – Practice protecting data with encryption and hashing
Exercise 10.3 – Practice protecting data with decryption
Exercise 10.4 – Explore topics
Summary
Working with Databases Using Entity Framework Core
Understanding modern databases
Understanding legacy Entity Framework
Understanding Entity Framework Core
Using a sample relational database
Setting up SQLite for macOS
Setting up SQLite for Windows
Creating the Northwind sample database for SQLite
Managing the Northwind sample database with SQLiteStudio
Setting up EF Core
Choosing an EF Core database provider
Setting up the dotnet-ef tool
Connecting to the database
Defining EF Core models
EF Core conventions
EF Core annotation attributes
EF Core Fluent API
Understanding data seeding
Building an EF Core model
Defining the Category and Product entity classes
Defining the Northwind database context class
Scaffolding models using an existing database
Querying EF Core models
Filtering included entities
Filtering and sorting products
Getting the generated SQL
Logging EF Core
Logging with query tags
Pattern matching with Like
Defining global filters
Loading patterns with EF Core
Eager loading entities
Enabling lazy loading
Explicit loading entities
Manipulating data with EF Core
Inserting entities
Updating entities
Deleting entities
Pooling database contexts
Transactions
Defining an explicit transaction
Practicing and exploring
Exercise 11.1 – Test your knowledge
Exercise 11.2 – Practice exporting data using different serialization formats
Exercise 11.3 – Explore the EF Core documentation
Summary
Querying and Manipulating Data Using LINQ
Writing LINQ queries
Extending sequences with the Enumerable class
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 a single property using OrderBy
Sorting by a subsequent property using ThenBy
Filtering by type
Working with sets and bags using LINQ
Using LINQ with EF Core
Building an EF Core model
Filtering and sorting sequences
Projecting sequences into new types
Joining and grouping sequences
Aggregating sequences
Sweetening LINQ syntax with syntactic sugar
Using multiple threads with parallel LINQ
Creating an app that benefits from multiple threads
Using Windows 10
Using macOS
For all operating systems
Creating your own LINQ extension methods
Working with LINQ to XML
Generating XML using LINQ to XML
Reading XML using LINQ to XML
Practicing and exploring
Exercise 12.1 – Test your knowledge
Exercise 12.2 – Practice querying with LINQ
Exercise 12.3 – Explore topics
Summary
Improving Performance and Scalability Using Multitasking
Understanding processes, threads, and tasks
Monitoring performance and resource usage
Evaluating the efficiency of types
Monitoring performance and memory use
Implementing the Recorder class
Measuring the efficiency of processing strings
Running tasks asynchronously
Running multiple actions synchronously
Running multiple actions asynchronously using tasks
Waiting for tasks
Continuing with another task
Nested and child tasks
Synchronizing access to shared resources
Accessing a resource from multiple threads
Applying a mutually exclusive lock to a resource
Understanding the lock statement and avoiding deadlocks
Synchronizing events
Making CPU operations atomic
Applying other types of synchronization
Understanding async and await
Improving responsiveness for console apps
Improving responsiveness for GUI apps
Improving scalability for web applications and web services
Common types that support multitasking
Using await in catch blocks
Working with async streams
Practicing and exploring
Exercise 13.1 – Test your knowledge
Exercise 13.2 – Explore topics
Summary
Introducing Practical Applications of C# and .NET
Understanding app models for C# and .NET
Building websites using ASP.NET Core
Building websites using a web content management system
Understanding web applications
Building and consuming web services
Building intelligent apps
New features in ASP.NET Core
ASP.NET Core 1.0
ASP.NET Core 1.1
ASP.NET Core 2.0
ASP.NET Core 2.1
ASP.NET Core 2.2
ASP.NET Core 3.0
ASP.NET Core 3.1
Blazor WebAssembly 3.2
ASP.NET Core 5.0
Understanding SignalR
Understanding Blazor
JavaScript and friends
Silverlight – C# and .NET using a plugin
WebAssembly – a target for Blazor
Blazor on the server side or client side
Understanding the bonus chapters
Building cross-platform mobile and desktop apps
Building Windows desktop apps using legacy technologies
Building an entity data model for Northwind
Creating a class library for Northwind entity models
Generating entity models using dotnet-ef
Manually improving the class-to-table mapping
Creating a class library for a Northwind database context
Summary
Building Websites Using ASP.NET Core Razor Pages
Understanding web development
Understanding HTTP
Client-side web development
Understanding ASP.NET Core
Classic ASP.NET versus modern ASP.NET Core
Creating an ASP.NET Core project
Testing and securing the website
Controlling the hosting environment
Enabling static and default files
Exploring Razor Pages
Enabling Razor Pages
Defining a Razor Page
Using shared layouts with Razor Pages
Using code-behind files with Razor Pages
Using Entity Framework Core with ASP.NET Core
Configure Entity Framework Core as a service
Manipulating data using Razor Pages
Enabling a model to insert entities
Defining a form to insert new suppliers
Using Razor class libraries
Creating a Razor class library
Disabling compact folders
Implementing the employees feature using EF Core
Implementing a partial view to show a single employee
Using and testing a Razor class library
Configuring services and the HTTP request pipeline
Registering services
Configuring the HTTP request pipeline
Simplest possible ASP.NET Core website project
Practicing and exploring
Exercise 15.1 – Test your knowledge
Exercise 15.2 – Practice building a data-driven web page
Exercise 15.3 – Practice building web pages for console apps
Exercise 15.4 – Explore topics
Summary
Building Websites Using the Model-View-Controller Pattern
Setting up an ASP.NET Core MVC website
Creating and exploring an ASP.NET Core MVC website
Reviewing the ASP.NET Core MVC website
Reviewing the ASP.NET Core Identity database
Exploring an ASP.NET Core MVC website
Understanding ASP.NET Core MVC startup
Understanding the default MVC route
Understanding controllers and actions
Understanding the view search path convention
Unit testing MVC
Understanding filters
Using a filter to secure an action method
Using a filter to cache a response
Using a filter to define a custom route
Understanding entity and view models
Understanding views
Customizing an ASP.NET Core MVC website
Defining a custom style
Setting up the category images
Understanding Razor syntax
Defining a typed view
Reviewing the customized home page
Passing parameters using a route value
Understanding model binders
Validating the model
Understanding view helper methods
Querying a database and using display templates
Improving scalability using asynchronous tasks
Making controller action methods asynchronous
Using other project templates
Installing additional template packs
Practicing and exploring
Exercise 16.1 – Test your knowledge
Exercise 16.2 – Practice implementing MVC by implementing a category detail page
Exercise 16.3 – Practice improving scalability by understanding and implementing async action methods
Exercise 16.4 – Explore topics
Summary
Building Websites Using a Content Management System
Understanding the benefits of a CMS
Understanding basic CMS features
Understanding enterprise CMS features
Understanding CMS platforms
Understanding Piranha CMS
Open source libraries and licensing
Creating a Piranha CMS website
Exploring a Piranha CMS website
Editing site and page content
Creating a new top-level page
Creating a new child page
Reviewing the blog archive
Commenting on posts and pages
Exploring authentication and authorization
Exploring configuration
Testing the new content
Understanding routing
Understanding media
Understanding the application service
Understanding content types
Understanding component types
Understanding standard fields
Customizing the rich text editor
Reviewing the Standard page type
Reviewing the Standard archive and post types
Understanding standard blocks
Reviewing component types and standard blocks
Defining components, content types, and templates
Creating custom regions
Creating an entity data model
Creating custom page types
Creating custom view models
Defining custom content templates for content types
Configuring startup and importing from a database
Learning how to create content using the project template
Testing the Northwind CMS website
Uploading images and creating the catalog root
Importing category and product content
Managing catalog content
Reviewing how Piranha stores content
Practicing and exploring
Exercise 17.1 – Test your knowledge
Exercise 17.2 – Practice defining a block type for rendering YouTube videos
Exercise 17.3 – Explore topics
Summary
Building and Consuming Web Services
Building web services using the ASP.NET Core Web API
Understanding web service acronyms
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 customers repository and Web API controller
Specifying problem details
Controlling XML serialization
Documenting and testing web services
Testing GET requests using a browser
Testing HTTP requests with the REST Client extension
Understanding Swagger
Testing requests with Swagger UI
Consuming services using HTTP clients
Understanding HttpClient
Configuring HTTP clients using HttpClientFactory
Getting customers as JSON in the controller
Enabling Cross-Origin Resource Sharing
Implementing advanced features
Implementing a Health Check API
Implementing Open API analyzers and conventions
Implementing transient fault handling
Understanding endpoint routing
Configuring endpoint routing
Adding security HTTP headers
Securing web services
Understanding other communication technologies
Understanding Windows Communication Foundation (WCF)
Understanding gRPC
Practicing and exploring
Exercise 18.1 – Test your knowledge
Exercise 18.2 – Practice creating and deleting customers with HttpClient
Exercise 18.3 – Explore topics
Summary
Building Intelligent Apps Using Machine Learning
Understanding machine learning
Understanding the machine learning lifecycle
Understanding datasets for training and testing
Understanding machine learning tasks
Understanding Microsoft Azure Machine Learning
Understanding ML.NET
Understanding Infer.NET
Understanding ML.NET learning pipelines
Understanding model training concepts
Understanding missing values and key types
Understanding features and labels
Making product recommendations
Problem analysis
Data gathering and processing
Creating the NorthwindML website project
Creating the data and view models
Implementing the controller
Training the recommendation models
Implementing a shopping cart with recommendations
Testing the product recommendations website
Practicing and exploring
Exercise 19.1 – Test your knowledge
Exercise 19.2 – Practice with samples
Exercise 19.3 – Explore topics
Summary
Building Web User Interfaces Using Blazor
Understanding Blazor
Understanding Blazor hosting models
Understanding Blazor components
What is the deal with Blazor and Razor?
Comparing Blazor project templates
Reviewing the Blazor Server project template
Understanding CSS isolation
Running the Blazor Server project template
Reviewing the Blazor WebAssembly project template
Building components using Blazor Server
Defining and testing a simple component
Getting entities into a component
Abstracting a service for a Blazor component
Using Blazor forms
Defining forms using the EditForm component
Navigating Blazor routes
Building and using a customer form component
Building components using Blazor WebAssembly
Configuring the server for Blazor WebAssembly
Configuring the client for Blazor WebAssembly
Exploring Progressive Web App support
Practicing and exploring
Exercise 20.1 – Test your knowledge
Exercise 20.2 – Practice creating a component
Exercise 20.3 – Explore topics
Summary
Building Cross-Platform Mobile Apps
Understanding XAML
Simplifying code using XAML
Choosing common controls
Understanding markup extensions
Understanding Xamarin and Xamarin.Forms
How Xamarin.Forms extends Xamarin
Development tools for mobile first, cloud first
Mobile platform market share
Understanding additional functionality
Understanding the INotificationPropertyChanged interface
Understanding dependency services
Understanding Xamarin.Forms user interface components
Understanding the ContentPage view
Understanding the Entry and Editor controls
Understanding the ListView control
Building mobile apps using Xamarin.Forms
Adding Android SDKs
Creating a Xamarin.Forms solution
Creating an entity model with two-way data binding
Creating a component for dialing phone numbers
Creating views for the customers list and customer details
Implementing the customer list view
Implementing the customer detail view
Setting the main page for the mobile app
Testing the mobile app
Consuming a web service from a mobile app
Configuring the web service to allow insecure requests
Configuring the iOS app to allow insecure connections
Configuring the Android app to allow insecure connections
Adding NuGet packages for consuming a web service
Getting customers from the web service
Practicing and exploring
Exercise 21.1 – Test your knowledge
Exercise 21.2 – Explore topics
Summary
Summary
Index
← Prev
Back
Next →
← Prev
Back
Next →