C# 7 and .NET: Designing Modern Cross-platform Applications

Book Description

Explore C# and the .NET Core framework to create applications and optimize them with ASP.NET Core 2

Key Features

  • Get to grips with multi-threaded, concurrent, and asynchronous programming in C# and .NET Core
  • Develop modern, cross-platform applications with .NET Core 2.0 and C# 7.0
  • Create efficient web applications with ASP.NET Core 2.

Book Description

C# is a widely used programming language, thanks to its easy learning curve, versatility, and support for modern paradigms. The language is used to create desktop apps, background services, web apps, and mobile apps. .NET Core is open source and compatible with Mac OS and Linux. There is no limit to what you can achieve with C# and .NET Core.

This Learning Path begins with the basics of C# and object-oriented programming (OOP) and explores features of C#, such as tuples, pattern matching, and out variables. You will understand.NET Standard 2.0 class libraries and ASP.NET Core 2.0, and create professional websites, services, and applications. You will become familiar with mobile app development using Xamarin.Forms and learn to develop high-performing applications by writing optimized code with various profiling techniques.

By the end of C# 7 and .NET: Designing Modern Cross-platform Applications, you will have all the knowledge required to build modern, cross-platform apps using C# and .NET.

This Learning Path includes content from the following Packt products:

  • C# 7.1 and .NET Core 2.0 - Modern Cross-Platform Development - Third Edition by Mark J. Price
  • C# 7 and .NET Core 2.0 High Performance by Ovais Mehboob Ahmed Khan

What you will learn

  • Explore ASP.NET Core to create professional web applications
  • Master OOP with C# to increase code reusability and efficiency
  • Protect your data using encryption and hashing
  • Measure application performance using BenchmarkDotNet
  • Use design techniques to increase your application's performance
  • Learn memory management techniques in .NET Core
  • Understand tools and techniques to monitor application performance

Who this book is for

This Learning Path is designed for developers who want to gain a solid foundation in C# and .NET Core, and want to build cross-platform applications. To gain maximum benefit from this Learning Path, you must have basic knowledge of C#.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright
    1. C# 7 and .NET: Designing Modern Cross-platform Applications
  3. About Packt
    1. Why Subscribe?
    2. Packt.com
  4. Contributors
    1. About the Authors
    2. About the Reviewers
    3. Packt Is Searching for Authors Like You
  5. Preface
    1. Who This Book Is For
    2. What This Book Covers
    3. To Get the Most out of This Book
      1. Download the Example Code Files
      2. Download the color images
      3. Conventions Used
    4. Get in Touch
      1. Reviews
  6. Controlling the Flow and Converting Types
    1. Selection statements
      1. Using Visual Studio 2017
      2. Using Visual Studio Code on macOS, Linux, or Windows
      3. The if statement
        1. The code
        2. Pattern matching with the if statement
      4. The switch statement
        1. The code
        2. Pattern matching with the switch statement
    2. Iteration statements
      1. The while statement
      2. The do statement
      3. The for statement
      4. The foreach statement
    3. Casting and converting between types
      1. Casting from numbers to numbers
        1. Casting numbers implicitly
        2. Casting numbers explicitly
      2. Using the convert type
      3. Rounding numbers
      4. Converting from any type to a string
      5. Converting from a binary object to a string
      6. Parsing from strings to numbers or dates and times
    4. Handling exceptions when converting types
      1. The try statement
      2. Catching all exceptions
      3. Catching specific exceptions
    5. Checking for overflow
      1. The checked statement
      2. The unchecked statement
    6. Looking for help
      1. Microsoft Docs and MSDN
      2. Go to definition
      3. Stack Overflow
      4. Google
      5. Subscribing to blogs
      6. Design patterns
        1. Singleton pattern
    7. Summary
  7. Writing, Debugging, and Testing Functions
    1. Writing functions
      1. Writing a times table function
      2. Writing a function that returns a value
      3. Writing mathematical functions
        1. Formatting numbers for output
        2. Calculating factorials with recursion
    2. Debugging an application during development
      1. Creating an application with a deliberate bug
      2. Setting a breakpoint
      3. The debugging toolbar
      4. Debugging windows
      5. Stepping through code
      6. Customizing breakpoints
    3. Logging during development and runtime
      1. Instrumenting with Debug and Trace
        1. Writing to the default trace listener
        2. Configuring trace listeners
      2. Switching trace levels
    4. Unit testing functions
      1. Creating a class library that needs testing with Visual Studio 2017
      2. Creating a unit test project with Visual Studio 2017
      3. Creating a class library that needs testing with Visual Studio Code
      4. Writing unit tests
      5. Running unit tests with Visual Studio 2017
      6. Running unit tests with Visual Studio Code
    5. Summary
  8. Building Your Own Types with Object-Oriented Programming
    1. Talking about OOP
    2. Building class libraries
      1. Creating a class library with Visual Studio 2017
      2. Creating a class library with Visual Studio Code
      3. Defining a class
      4. Instantiating a class
        1. Referencing an assembly using Visual Studio 2017
        2. Referencing an assembly using Visual Studio Code
        3. Importing a namespace
      5. Managing multiple projects with Visual Studio Code
      6. Inheriting from System.Object
    3. Storing data with fields
      1. Defining fields
        1. Understanding access modifiers
      2. Storing a value using the enum keyword
      3. Storing multiple values using collections
      4. Making a field static
      5. Making a field constant
      6. Making a field read-only
      7. Initializing fields with constructors
      8. Setting fields with default literal
    4. Writing and calling methods
      1. Combining multiple values with tuples
        1. Defining methods with tuples
        2. Naming the fields of a tuple
        3. Inferring tuple names
        4. Deconstructing tuples
      2. Defining and passing parameters to methods
      3. Overloading methods
      4. Optional parameters and named arguments
    5. Controlling how parameters are passed
    6. Splitting classes using partial
    7. Controlling access with properties and indexers
      1. Defining read-only properties
      2. Defining settable properties
      3. Defining indexers
    8. Summary
  9. Implementing Interfaces and Inheriting Classes
    1. Setting up a class library and console application
      1. Using Visual Studio 2017
      2. Using Visual Studio Code
      3. Defining the classes
    2. Simplifying methods with operators
      1. Implementing some functionality with a method
      2. Implementing some functionality with an operator
    3. Defining local functions
    4. Raising and handling events
      1. Calling methods using delegates
      2. Defining events
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 or Visual Studio Code
    5. Implementing interfaces
      1. Common interfaces
      2. Comparing objects when sorting
        1. Attempting to sort objects without a method to compare
        2. Defining a method to compare
        3. Defining a separate comparer
    6. Making types more reusable with generics
      1. Making a generic type
      2. Making a generic method
    7. Managing memory with reference and value types
      1. Defining a struct type
      2. Releasing unmanaged resources
      3. Ensuring that dispose is called
    8. Inheriting from classes
      1. Extending classes
      2. Hiding members
      3. Overriding members
        1. Using Visual Studio 2017
        2. Using Visual Studio 2017 or Visual Studio Code
      4. Preventing inheritance and overriding
      5. Polymorphism
    9. Casting within inheritance hierarchies
      1. Implicit casting
      2. Explicit casting
      3. Handling casting exceptions
    10. Inheriting and extending .NET types
      1. Inheriting from an exception
      2. Extending types when you can't inherit
        1. Using static methods to reuse functionality
        2. Using extension methods to reuse functionality
    11. Summary
  10. Understanding and Packaging .NET Standard Types
    1. Understanding assemblies and namespaces
      1. Base Class Libraries and CoreFX
        1. Assemblies, NuGet packages, and platforms
        2. Namespaces
      2. Understanding dependent assemblies
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 and Visual Studio Code
      3. Relating assemblies and namespaces
        1. Browsing assemblies with Visual Studio 2017
        2. Using Visual Studio 2017 or Visual Studio Code
        3. Importing a namespace
      4. Relating C# keywords to .NET types
    2. Sharing code cross-platform with .NET Standard 2.0 class libraries
      1. Creating a .NET Standard 2.0 class library
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
    3. Understanding NuGet packages
      1. Understanding metapackages
      2. Understanding frameworks
      3. Fixing dependencies
    4. Publishing your applications for deployment
      1. Creating a console application to publish
      2. Publishing with Visual Studio 2017 on Windows
      3. Publishing with Visual Studio Code on macOS
    5. Packaging your libraries for NuGet distribution
      1. Understanding dotnet commands
      2. Adding a package reference
        1. Using Visual Studio Code
        2. Using Visual Studio 2017
      3. Packaging a library for NuGet
      4. Testing your package
        1. Using Visual Studio Code
        2. Using Visual Studio 2017
        3. Using Visual Studio 2017 and Visual Studio Code
    6. Porting from .NET Framework to .NET Core
      1. Could you port?
      2. Should you port?
      3. Differences between .NET Framework and .NET Core
      4. Understanding the .NET Portability Analyzer
      5. Using non-.NET Standard libraries
    7. Summary
  11. Using Common .NET Standard Types
    1. Working with numbers
      1. Working with big integers
      2. Working with complex numbers
    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. Other string members
      7. Building strings efficiently
      8. Pattern matching with regular expressions
        1. The syntax of a regular expression
        2. Examples of regular expressions
    3. Working with collections
      1. Common features of all collections
      2. Understanding collections
        1. Lists
        2. Dictionaries
        3. Stacks
        4. Queues
        5. Sets
      3. Working with lists
      4. Working with dictionaries
      5. Sorting collections
      6. Using specialized collections
      7. Using immutable collections
    4. Working with network resources
      1. Working with URIs, DNS, and IP addresses
      2. Pinging a server
    5. Working with types and attributes
      1. Versioning of assemblies
      2. Reading assembly metadata
      3. Creating custom attributes
      4. Doing more with reflection
    6. Internationalizing your code
      1. Globalizing an application
    7. Summary
  12. Working with Files, Streams, and Serialization
    1. Managing the filesystem
      1. Handling cross-platform environments and filesystems
        1. Using Windows 10
        2. Using macOS
      2. Managing drives
      3. Managing directories
      4. Managing files
      5. Managing paths
      6. Getting file information
      7. Controlling files
    2. Reading and writing with streams
      1. Writing to text and XML streams
        1. Writing to text streams
        2. Writing to XML streams
      2. Disposing of file resources
        1. Implementing disposal with try statement
        2. Simplifying disposal with the using statement
      3. Compressing streams
    3. Encoding text
      1. Encoding strings as byte arrays
      2. Encoding and decoding text in files
    4. Serializing object graphs
      1. Serializing with XML
      2. Deserializing with XML
      3. Customizing the XML
      4. Serializing with JSON
      5. Serializing with other formats
    5. Summary
  13. Improving Performance and Scalability Using Multitasking
    1. Monitoring performance and resource usage
      1. Evaluating the efficiency of types
      2. Monitoring performance and memory use
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Creating the Recorder class
        4. Measuring the efficiency of processing strings
    2. Understanding processes, threads, and tasks
    3. Running tasks asynchronously
      1. Running multiple actions synchronously
      2. Running multiple actions asynchronously using tasks
      3. Waiting for tasks
      4. Continuing with another task
      5. Nested and child tasks
    4. Synchronizing access to shared resources
      1. Accessing a resource from multiple threads
      2. Applying a mutually exclusive lock to a resource
      3. Understanding the lock statement
      4. Making 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. Await in catch blocks
    6. Summary
  14. Building Web Sites Using ASP.NET Core Razor Pages
    1. Understanding web development
      1. Understanding HTTP
      2. Client-side web development
    2. Understanding ASP.NET Core
      1. Classic ASP.NET versus modern ASP.NET Core
      2. Creating an ASP.NET Core project with Visual Studio 2017
      3. Creating an ASP.NET Core project with Visual Studio Code
      4. Reviewing the ASP.NET Core Empty project template
      5. Testing the empty website
      6. Enabling static files
      7. Enabling default files
    3. Exploring Razor Pages
      1. Enabling Razor Pages
      2. Defining a Razor Page
      3. Using shared layouts with Razor Pages
        1. Setting a shared layout
        2. Defining a shared layout
      4. Using code-behind files with Razor Pages
    4. Using Entity Framework Core with ASP.NET Core
      1. Creating Entity models for Northwind
        1. Creating a class library for the Northwind entity classes
        2. Defining the entity classes
        3. Creating a class library for Northwind database context
          1. Using Visual Studio 2017
          2. Using Visual Studio Code
        4. Defining the database context class
      2. Configure Entity Framework Core as a service
      3. Manipulating data
    5. Summary
  15. Building Web Sites Using ASP.NET Core MVC
    1. Setting up an ASP.NET Core MVC website
      1. Creating an ASP.NET Core MVC website
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
      2. Reviewing the ASP.NET Core MVC project template
      3. Performing database migrations
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
      4. Testing the ASP.NET MVC website
      5. Reviewing authentication with ASP.NET Identity
    2. Understanding an ASP.NET Core MVC website
      1. ASP.NET Core startup
      2. Understanding the default route
      3. Understanding ASP.NET Core MVC controllers
      4. Understanding ASP.NET Core MVC models
        1. Configuring an EF Core entity data model
        2. Creating view models for requests
        3. Fetch the model in the controller
      5. Understanding ASP.NET Core MVC views
        1. Rendering the Home controller's views
        2. Sharing layouts between views
        3. Defining custom styles
        4. Defining a typed view
      6. Passing parameters using a route value
      7. Passing parameters using a query string
    3. Summary
  16. Building Web Services and Applications Using ASP.NET Core
    1. Building web services using ASP.NET Core Web API
      1. Understanding ASP.NET Core controllers
      2. Creating an ASP.NET Core Web API project
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 and Visual Studio Code
      3. Creating a web service for the Northwind database
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 and Visual Studio Code
      4. Creating data repositories for entities
        1. Configuring and registering the customers repository
        2. Creating the Web API controller
    2. Documenting and testing web services using Swagger
      1. Testing GET requests with any browser
      2. Testing POST, PUT, and DELETE requests with Swagger
      3. Installing a Swagger package
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 and Visual Studio Code
      4. Testing GET requests with Swagger UI
      5. Testing POST requests with Swagger UI
    3. Building SPAs using Angular
      1. Understanding the Angular project template
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 and Visual Studio Code
      2. Calling NorthwindService
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 and Visual Studio Code
        4. Modifying the home component to call NorthwindService
      3. Testing the Angular component calling the service
        1. Using Visual Studio 2017
        2. Using Visual Studio Code
        3. Using Visual Studio 2017 and Visual Studio Code
    4. Using other project templates
      1. Installing additional template packs
    5. Summary
  17. Building Windows Apps Using XAML and Fluent Design
    1. Understanding the modern Windows platform
      1. Understanding Universal Windows Platform
      2. Understanding Fluent Design System
        1. Filling user interface elements with acrylic brushes
        2. Connecting user interface elements with animations
        3. Parallax views and Reveal lighting
      3. Understanding XAML Standard 1.0
        1. Simplifying code using XAML
        2. Choosing common controls
    2. Creating a modern Windows app
      1. Enabling developer mode
      2. Creating a UWP project
      3. Exploring common controls and acrylic brushes
      4. Exploring Reveal
      5. Installing more controls
    3. Using resources and templates
      1. Sharing resources
      2. Replacing a control template
    4. Data binding
      1. Binding to elements
      2. Binding to data sources
        1. Modifying the NorthwindService
        2. Creating the Northwind app
    5. Building apps using Windows Template Studio
      1. Installing Windows Template Studio
      2. Selecting project types, frameworks, pages, and features
      3. Retargeting the project
      4. Customizing some views
      5. Testing the app's functionality
    6. Summary
  18. Building Mobile Apps Using XAML and Xamarin.Forms
    1. Understanding Xamarin and Xamarin.Forms
      1. How Xamarin.Forms extends Xamarin
      2. Mobile first, cloud first
    2. Building mobile apps using Xamarin.Forms
      1. Adding Android SDKs
      2. Creating a Xamarin.Forms solution
      3. Creating a model
      4. Creating an interface for dialing phone numbers
        1. Implement the phone dialer for iOS
        2. Implement the phone dialer for Android
      5. Creating views for the customers list and customer details
        1. Creating the view for the list of customers
        2. Creating the view for the customer details
      6. Testing the mobile app with iOS
      7. Adding NuGet packages for calling a REST service
      8. Getting customers from the service
    3. Summary
  19. Understanding .NET Core Internals and Measuring Performance
    1. .NET Core internals
      1. CoreFX
      2. CoreCLR
      3. Understanding MSIL, CLI, CTS, and CLS
      4. How the CLR works
      5. From compilation to execution – Under the hood
      6. Garbage collection
        1. Generations in GC
      7. .NET Native and JIT compilation
    2. Utilizing multiple cores of the CPU for high performance
    3. How releasing builds increases performance
    4. Benchmarking .NET Core 2.0 applications
      1. Exploring BenchmarkDotNet
      2. How it works
      3. Setting parameters
      4. Memory diagnostics using BenchmarkDotnet
      5. Adding configurations
    5. Summary
  20. Data Structures and Writing Optimized Code in C#
    1. What are data structures?
    2. Understanding the use of Big O notation to measure the performance and complexity of an algorithm
      1. Logarithms
    3. Choosing the right data structure for performance optimization
      1. Arrays
      2. Lists
      3. Stacks
      4. Queue
      5. Linked lists
        1. Singly linked lists
        2. Doubly linked lists
        3. Circular linked lists
      6. Dictionaries, hashtables, and hashsets
      7. Generic lists
    4. Best practices in writing optimized code in C#
      1. Boxing and unboxing overhead
      2. String concatenation
      3. Exception handling
      4. For and foreach
      5. Delegates
    5. Summary
  21. Designing Guidelines for .NET Core Application Performance
    1. Coding principles
      1. Naming convention
      2. Code comments
      3. One class per file
      4. One logic per method
    2. Design principles
      1. KISS (Keep It Simple, Stupid)
      2. YAGNI (You Aren't Gonna Need It)
      3. DRY (Don't Repeat Yourself)
      4. Separation of Concerns (SoC)
      5. SOLID principles
        1. Single Responsibility Principle
        2. Open Closed principle
          1. Parameters
          2. Inheritance
          3. Composition
        3. Liskov principle
        4. The Interface Segregation principle
        5. The Dependency Inversion principle
      6. Caching
      7. Data structures
      8. Communication
        1. Using lighter interfaces
        2. Minimizing message size
        3. Queuing communication
      9. Resource management
        1. Avoiding improper use of threads
        2. Disposing objects in a timely fashion
        3. Acquiring resources when they are required
      10. Concurrency
    3. Summary
  22. Memory Management Techniques in .NET Core
    1. Memory allocation process overview
    2. Analysing CLR internals through the SOS debugger in .NET Core
    3. Memory fragmentation
    4. Avoiding finalizers
    5. Best practices for disposing of objects in .NET Core
      1. Introduction to the IDisposable interface
      2. What are unmanaged resources?
      3. Using IDisposable
      4. When to implement the IDisposable interface
      5. Finalizer and Dispose
    6. Summary
  23. Microservices Architecture
    1. Microservices architecture
      1. Benefits of microservices architecture
      2. Standard practice when developing microservices
      3. Types of microservices
        1. Stateless microservices
        2. Stateful microservices
      4. DDD
      5. Data manipulation with microservices
        1. Wrapping microservices behind an API gateway
        2. Denormalizing data into a flat schema for read/query purposes
      6. Consistency across business scenarios
      7. Communication with microservices
      8. Database architecture in microservices
        1. Tables per service
        2. Database per service
        3. Challenges in segregating tables or databases per service
      9. What is API composition?
      10. CQRS
    2. Developing microservices architecture with .NET Core
      1. Creating a sample app in .NET Core using microservices architecture
        1. Solution structure
        2. Logical architecture
        3. Developing a Core infrastructure project
          1. Creating the BaseEntity class
          2. The UnitOfWork pattern
          3. Creating a repository interface
          4. Logging
          5. Creating the APIComponents infrastructure project
        4. Developing an identity service for user authorization
          1. OpenIddict connect flows
          2. Creating the identity service project
        5. Implementing the vendor service
        6. Creating a vendor domain
        7. Creating the vendor infrastructure
        8. Creating the vendor service
        9. Implementing the mediator pattern in the vendor service
    3. Deploying microservices on Docker containers
      1. What is Docker?
      2. Using Docker with .NET Core
      3. Running Docker images
    4. Summary
  24. Other Books You May Enjoy
    1. Leave a Review - Let Other Readers Know What You Think

Product Information

  • Title: C# 7 and .NET: Designing Modern Cross-platform Applications
  • Author(s): Mark J. Price, Ovais Mehboob Ahmed Khan
  • Release date: December 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789956696