Home Page Icon
Home Page
Table of Contents for
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition
Close
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition
by Mark J. Price
C# 7 and .NET Core
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Hello, C#! Welcome, .NET Core!
Choosing your development environment
Using alternative C# IDEs
Deploying cross-platform
Installing Microsoft Visual Studio 2017 for Windows
Choosing workloads
Choosing additional components
Signing in to Visual Studio 2017
Choosing your settings
Reviewing Visual Studio's user interface
Installing Microsoft Visual Studio Code for Windows, macOS, or Linux
Installing Microsoft Visual Studio Code for macOS
Installing .NET Core for macOS
Installing Homebrew
Installing OpenSSL
Installing .NET Core SDK
Installing the Visual Studio Code extension for C#
Understanding .NET
Understanding .NET Framework
Understanding the Mono and Xamarin projects
Understanding .NET Core
Streamlining .NET
Understanding .NET Standard
.NET used in this book
Understanding .NET Native
Comparing .NET technologies
Writing and compiling code using the .NET Core CLI tool
Writing code using a simple text editor
If you are using Windows Notepad
If you are using macOS TextEdit
Compiling code using the .NET Core CLI tool
Restoring packages and running the application
Fixing compiler errors
Understanding Intermediate Language
Writing and compiling code using Microsoft Visual Studio 2017
Writing code using Microsoft Visual Studio 2017
Coding with Visual Studio's editor
Compiling code using Visual Studio 2017
Fixing mistakes with the error list
Adding existing projects to Visual Studio 2017
Autoformatting code
Experimenting with C# Interactive
Other useful windows
Writing and compiling code using Microsoft Visual Studio Code
Writing code using Visual Studio Code
Compiling code using Visual Studio Code
Managing source code with GitHub
Using Git with Visual Studio 2017
Using the Team Explorer window
Cloning a GitHub repository
Managing a GitHub repository
Using Git with Visual Studio Code
Configuring Git at the command line
Managing Git with Visual Studio Code
Practicing and exploring
Exercise 1.1 - test your knowledge
Exercise 1.2 - practice coding anywhere
Exercise 1.3 - explore topics
Summary
2. Speaking C#
Understanding C# basics
Using Visual Studio 2017
Using Visual Studio Code on macOS, Linux, or Windows
C# grammar
Statements
Comments
Blocks
C# vocabulary
C# keywords
Writing the code
Verbs are methods
Nouns are types, fields, and variables
Counting types and methods
Building and running with Visual Studio 2017
Building and running with Visual Studio Code
Declaring variables
Naming variables
Literal values
Storing text
Storing numbers
Storing whole numbers
C# 7 improvements
Storing real numbers
Using Visual Studio 2017
Using Visual Studio Code
Writing code to explore numbers
Comparing double and decimal
Storing Booleans
The object type
The dynamic type
Local variables
Inferring the type of a local variable
Making a value type nullable
Checking for null
Storing multiple values in an array
Building console applications
Displaying output to the user
Getting input from the user
Importing a namespace
Simplifying the usage of the console
Reading arguments and working with arrays
Passing arguments with Visual Studio 2017
Passing arguments with Visual Studio Code
Viewing the output
Enumerating arguments
Running on Windows
Running on macOS
Handling platforms that do not support an API
Operating on variables
Experimenting with unary operators
Experimenting with arithmetic operators
Comparison and Boolean operators
Practicing and exploring
Exercise 2.1 - test your knowledge
Exercise 2.2 - practice number sizes and ranges
Exercise 2.3 - explore topics
Summary
3. Controlling the Flow, Converting Types, and Handling Exceptions
Selection statements
Using Visual Studio 2017
Using Visual Studio Code on macOS, Linux, or Windows
The if statement
Pattern matching with the if statement
The switch statement
Pattern matching with the switch statement
Iteration statements
The while statement
The do statement
The for statement
The foreach statement
How does the foreach statement work?
Casting and converting between types
Casting from numbers to numbers
Casting explicitly
Using the convert type
Rounding numbers
Converting from any type to a string
Parsing from strings to numbers or dates and times
Handling exceptions
The try statement
Catching all exceptions
Catching specific exceptions
The finally statement
Simplifying disposal with the using statement
Checking for overflow
The checked statement
The unchecked statement
Looking for help
Microsoft Docs and MSDN
Go to definition
StackOverflow
Google
Subscribing to blogs
Design patterns
Singleton pattern
Practice and explore
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 - explore topics
Summary
4. Using .NET Standard Types
Using assemblies and namespaces
Comparing .NET Framework with .NET Core
Base Class Libraries and CoreFX
Assemblies, NuGet packages, and platforms
Namespaces
Referencing a dependent assembly
Browsing assemblies with Visual Studio 2017
Understanding .NET Core project files
Relating assemblies and namespaces
Importing a namespace
Relating C# keywords to .NET types
Storing and manipulating 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
Other string members
Building strings efficiently
Pattern matching with regular expressions
The syntax of a regular expression
Examples of regular expressions
Storing data with collections
Understanding collections
Lists
Dictionaries
Stacks
Queues
Sets
Working with lists
Working with dictionaries
Sorting collections
Using specialized collections
Internationalizing an application
Globalizing an application
Practicing and exploring
Exercise 4.1 - test your knowledge
Exercise 4.2 - practice regular expressions
Exercise 4.3 - explore topics
Summary
5. Debugging, Monitoring, and Testing
Debugging tools
Debugging an application
Setting a breakpoint
The debugging toolbar
Debugging windows
Stepping through code
Customizing breakpoints
Monitoring performance and resource usage
Evaluating the efficiency of types
Monitoring performance and memory use
Measuring the efficiency of processing strings
Unit testing an application
Creating a class library that needs testing with Visual Studio 2017
Creating a unit test project with Visual Studio 2017
Creating a class library that needs testing with Visual Studio Code
Writing unit tests
Running unit tests with Visual Studio 2017
Running unit tests with Visual Studio Code
Practicing and exploring
Exercise 5.1 - test your knowledge
Exercise 5.2 - practice debugging and unit testing
Exercise 5.3 - explore topics
Summary
6. Building Your Own Types with Object-Oriented Programming
Talking about OOP
Building class libraries
Creating a class library with Visual Studio 2017
Creating a class library with Visual Studio Code
Defining a class
Instantiating a class
Referencing an assembly using Visual Studio 2017
Referencing an assembly using Visual Studio Code
Importing a namespace
Managing multiple projects with Visual Studio Code
Inheriting from System.Object
Storing data with fields
Defining fields
Understanding access modifiers
Storing a value using the enum keyword
Storing multiple values using collections
Making a field static
Making a field constant
Making a field read-only
Initializing fields with constructors
Writing and calling methods
Combining multiple values with tuples
Referencing the System.ValueTuple package with Visual Studio 2017
Referencing the System.ValueTuple package with Visual Studio Code
Defining methods with tuples
Naming the fields of a tuple
Deconstructing tuples
Defining and passing parameters to methods
Overloading methods
Optional parameters and named arguments
Controlling how parameters are passed
Splitting classes using partial
Controlling access with properties and indexers
Defining read-only properties
Defining settable properties
Defining indexers
Practicing and exploring
Exercise 6.1 - test your knowledge
Exercise 6.2 - practice writing mathematical methods
Exercise 6.3 - explore topics
Summary
7. Implementing Interfaces and Inheriting Classes
Setting up a class library and console application
Using Visual Studio 2017
Using Visual Studio Code
Defining the classes
Simplifying methods with operators
Implementing some functionality with a method
Implementing some functionality with an operator
Defining local functions
Raising and handling events
Calling methods using delegates
Defining events
Implementing interfaces
Common interfaces
Comparing objects when sorting
Defining a separate comparer
Managing memory with reference and value types
Defining a struct type
Releasing unmanaged resources
Ensuring that dispose is called
Inheriting from classes
Extending classes
Hiding members
Overriding members
Preventing inheritance and overriding
Polymorphism
Casting within inheritance hierarchies
Implicit casting
Explicit casting
Handling casting exceptions
Inheriting and extending .NET types
Inheriting from an exception
Extending types when you can't inherit
Using static methods to reuse functionality
Using extension methods to reuse functionality
Practice and explore
Exercise 7.1 - test your knowledge
Exercise 7.2 - practice creating an inheritance hierarchy
Exercise 7.3 - explore topics
Summary
8. Working with Databases Using the Entity Framework Core
Relational Database Management Systems
Using a sample database
Using Microsoft SQL Server on Windows
Connecting to Microsoft SQL Server LocalDb
Creating the Northwind sample database
Managing the Northwind sample database
Using SQLite on macOS and mobile platforms
Running a script for SQLite
Choosing a .NET data provider
Connecting to the database
Setting up Entity Framework Core
Using Visual Studio 2017
Using Visual Studio Code
Entity Framework Core models
EF Core conventions
EF Core annotation attributes
EF Core Fluent API
Building an EF Core Model
Querying an EF Core model
Logging EF Core
Loading patterns with EF Core
Eager and lazy loading entities
Explicit loading entities
Manipulating data with EF Core
Inserting entities
Updating entities
Deleting entities
Transactions
Defining an explicit transaction
Practicing and exploring
Exercise 8.1 - test your knowledge
Exercise 8.2 - explore the EF Core documentation
Summary
9. Querying and Manipulating Data with 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 with OrderBy
Sorting by multiple properties with the ThenBy method
Working with sets
Projecting entities with Select
Building an EF Core model
Joining and grouping
Sweetening the syntax with syntactic sugar
Using multiple threads with parallel LINQ
Creating your own LINQ extension methods
Working with LINQ to XML
Generating XML using LINQ to XML
Reading XML by using LINQ to XML
Practicing and exploring
Exercise 9.1 - test your knowledge
Exercise 9.2 - practice querying with LINQ
Exercise 9.3 - explore topics
Summary
10. Working with Files, Streams, and Serialization
Managing the filesystem
Managing directories
Managing files
Managing paths
Getting file information
Reading and writing with streams
Writing to text and XML streams
Compressing streams
Encoding text
Encoding strings as byte arrays
Encoding and decoding text in files
Serializing object graphs
Serializing with XML
Deserializing with XML
Customizing the XML
Serializing with JSON
Serializing with other formats
Practice and explore
Exercise 10.1 - test your knowledge
Exercise 10.2 - practice serializing as XML
Exercise 10.3 - explore serialization formats
Exercise 10.4 - explore topics
Summary
11. Protecting Your Data
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
Using Visual Studio 2017
Using Visual Studio Code
Creating the Protector class
Hashing data
Hashing with SHA256
Signing data
Signing with SHA256 and RSA
Practicing and exploring
Exercise 11.1 - test your knowledge
Exercise 11.2 - practice protecting data with encryption and hashing
Exercise 11.3 - practice protecting data with decryption
Exercise 11.4 - explore topics
Summary
12. Improving Performance and Scalability with Multitasking
Understanding processes, threads, and tasks
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
Making operations atomic
Applying other types of synchronization
Implementing multitasking for a GUI
Creating a GUI that blocks
Creating a GUI that doesn't block
Other types with Async methods
await in catch blocks
Improving scalability for client-server applications
Practicing and exploring
Exercise 12.1 - test your knowledge
Exercise 12.2 - explore topics
Summary
13. Building Universal Windows Platform Apps Using XAML
Understanding Universal Windows Platform
Adapting your app's layout
Taking advantage of unique device capabilities
Understanding XAML
Simplifying code using XAML
Choosing common controls
Creating an app for Universal Windows Platform
Using resources and templates
Sharing resources
Replacing a control template
Data binding
Binding to elements
Binding to data
Animating with storyboards
Testing in emulators
Practicing and exploring
Exercise 13.1 - test your knowledge
Exercise 13.2 - practice building a universal tip calculator
Exercise 13.3 - explore topics
Summary
14. Building Web Applications Using ASP.NET Core MVC
Understanding ASP.NET Core
Classic ASP.NET versus modern ASP.NET Core
Client-side web development
Understanding HTTP
Creating an ASP.NET Core project with Visual Studio 2017
Performing database migrations
Reviewing authentication with ASP.NET Identity
Creating an ASP.NET Core project with Visual Studio Code
Managing client-side packages with Bower
Exploring an ASP.NET Core MVC web application
ASP.NET Core startup
Understanding the default route
ASP.NET Core MVC controllers
ASP.NET Core MVC models
Create Entity models for Northwind
Configure Entity Framework Core as a service
Create view models for requests
Fetch the model in the controller
ASP.NET Core MVC views
Rendering the Home controller's views
Sharing layouts between views
Defining custom styles
Defining a typed view
Taking ASP.NET Core MVC further
Passing parameters using a route value
Passing parameters using a query string
Annotating models
Practicing and exploring
Exercise 14.1 - test your knowledge
Exercise 14.2 - practice building a data-driven web application
Exercise 14.3 - explore topics
Summary
15. Building Mobile Apps Using Xamarin.Forms and ASP.NET Core Web API
Understanding Xamarin.Forms
How Xamarin.Forms extends Xamarin
Mobile first, cloud first
Installing Xcode
Installing Visual Studio for Mac
Building services using ASP.NET Core Web API and Visual Studio Code
Creating an ASP.NET Core Web API project
Creating a web service for the Northwind database
Creating the Northwind database
Referencing the EF Core NuGet packages
Creating the entity model and database context
Creating the data repository
Configuring and registering the data repository
Set the database connection string
Creating the Web API controller
Testing the web service
Testing GET requests with any browser
Testing POST, PUT, DELETE, and other requests with Postman
Building mobile apps using Xamarin.Forms and Visual Studio for Mac
Creating a Xamarin.Forms project
Creating a model
Creating an interface for dialing phone numbers and implement for iOS and Android
Creating views for the customers list and customer details
Test the mobile app with iOS
Adding NuGet packages for calling a REST service
Getting customers from the service
Practicing and exploring
Exercise 15.1 - test your knowledge
Exercise 15.2 - explore topics
Summary
16. Packaging and Deploying Your Code Cross-Platform
Porting to .NET Core
Could you port?
Should you port?
Differences between .NET Framework and .NET Core
Understanding the .NET Portability Analyzer
Sharing code cross-platform with .NET Standard class libraries
Creating a .NET Standard class library
Using Visual Studio 2017
Using Visual Studio Code on macOS
Understanding NuGet packages
Referencing packages
Understanding metapackages
Understanding Frameworks
Fixing dependencies
Switching to a different .NET Standard
Publishing your applications
Creating a console application to publish
Publishing with Visual Studio 2017
Publishing with Visual Studio Code
Deploying to the cloud
Creating an ASP.NET Core MVC web application to publish
Register an Azure account
Create an Azure web app
Publishing an ASP.NET web application to the web app
Developing on and for Linux
Practicing and exploring
Exercise 16.1 - test your knowledge
Exercise 16.2 - explore topics
Summary
A. Answers to the Test Your Knowledge Questions
Chapter 1 - Hello, C#! Welcome, .NET Core!
Chapter 2 - Speaking C#
Chapter 3 - Controlling the Flow, Converting Types, and Handling Exceptions
Chapter 4 - Using .NET Standard Types
Chapter 5 - Debugging, Monitoring, and Testing
Chapter 6 - Building Your Own Types with Object-Oriented Programming
Chapter 7 - Implementing Interfaces and Inheriting Classes
Chapter 8 - Working with Databases Using Entity Framework Core
Chapter 9 - Querying and Manipulating Data with LINQ
Chapter 10 - Working with Files, Streams, and Serialization
Chapter 11 - Protecting Your Data
Chapter 12 - Improving Performance and Scalability with Multitasking
Chapter 13 - Building Universal Windows Platform Apps Using XAML
Chapter 14 - Building Web Applications Using ASP.NET Core MVC
Chapter 15 - Building Mobile Apps Using Xamarin.Forms and ASP.NET Core Web API
Chapter 16 - Packaging and Deploying Your Code Cross-Platform
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Table of Contents
Next
Next Chapter
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition
C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset