Book Image

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

By : Mark J. Price, Ovais Mehboob Ahmed Khan
Book Image

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

By: Mark J. Price, Ovais Mehboob Ahmed Khan

Overview of this book

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
Table of Contents (25 chapters)
Title Page
Copyright
About Packt
Contributors
Preface
16
Designing Guidelines for .NET Core Application Performance
Index

Preface

C# is a widely used programming language, thanks to its easy learning curve, versatility, and support for modern paradigms. It is used to create desktop apps, background services, web apps, and mobile apps. Also, the .NET Core is open sourced and is compatible with Mac OS and Linux apart from Windows. Thus, there is no limit to what you can achieve with C# and .NET Core. This Learning Path is your one-stop solution for building powerful cross-platform apps with C# 7 and .NET Core 2.0. It begins with the basics of C# and object-oriented programming and explores features of C#, such as tuples, pattern matching, out variables, and so on. You will explore .NET Standard 2.0 class libraries, ASP.NET Core 2.0, and learn how to 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 this Learning Path, you will have all the knowledge required to build modern, cross-platform apps using C# and .NET.

Who This Book Is For

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

What This Book Covers

Chapter 1Controlling the Flow and Converting Types, talks about writing code that makes decisions, repeats a block of statements, and converts between types, and writing code defensively to handle errors when they inevitably occur. You will also learn the best places to look for help.

Chapter 2Writing, Debugging, and Testing Functions, is about following the Don't Repeat Yourself (DRY) principle by writing reusable functions, and learning how to use debugging tools to track down and remove bugs, monitoring your code while it executes to diagnose problems, and rigorously testing your code to remove bugs and ensure stability and reliability before it gets deployed into production.

Chapter 3Building Your Own Types with Object-Oriented Programming, discusses all the different categories of members that a type can have, including fields to store data and methods to perform actions. You will use OOP concepts, such as aggregation and encapsulation. You will learn the C# 7 language features such as tuple syntax support and out variables, and C# 7.1 language features such as default literals and inferred tuple names.

Chapter 4Implementing Interfaces and Inheriting Classes, explains deriving new types from existing ones using object-oriented programming (OOP). You will learn how to define operators and C# 7 local functions, delegates and events, how to implement interfaces of the base and derived classes, how to override a type member, how to use polymorphism, how to create extension methods, and how to cast between classes in an inheritance hierarchy.

Chapter 5Understanding and Packaging .NET Standard Types, presents .NET Core 2.0 types that are part of .NET Standard 2.0, and how they are related to C#.  You will learn how to deploy and package your own apps and libraries.

Chapter 6Using Common .NET Standard Types, discusses the .NET Standard types that allow your code to perform common practical tasks, such as manipulating numbers and text, storing items in collections, and implementing internationalization.

Chapter 7Working with Files, Streams, and Serialization, talks about interacting with the filesystem, reading and writing to files and streams, text encoding, and serialization.

Chapter 8, Improving Performance and Scalability Using Multitasking, discusses allowing multiple actions to occur at the same time to improve performance, scalability, and user productivity. You will learn about the C# 7.1 async Main feature, and how to use types in the System.Diagnostics namespace to monitor your code to measure performance and efficiency.

Chapter 9Building Web Sites Using ASP.NET Core Razor Pages, is about learning the basics of building websites with a modern HTTP architecture on the server-side using ASP.NET Core. You will learn the new ASP.NET Core feature known as Razor Pages that simplifies creating web pages for small websites.

Chapter 10Building Web Sites Using ASP.NET Core MVC, is about learning how to build large, complex websites in a way that is easy to unit test and manage with teams of programmers using ASP.NET Core. You will learn about startup configuration, authentication, routes, models, views, and controllers in ASP.NET Core MVC.

 

 

 

 

 

 

Chapter 11Building Web Services and Applications Using ASP.NET Core, explains building web applications with a combination of a modern frontend technology, such as Angular or React, and a backend REST architecture web service using ASP.NET Core Web API.

Chapter 12Building Windows Apps Using XAML and Fluent Design, talks about learning the basics of XAML that can be used to define the user interface for a graphical app for the Universal Windows Platform (UWP), and applying principles and features of Fluent Design to light it up. This app can then run on any device running Windows 10, Xbox One, and even Mixed Reality devices such as HoloLens.

Chapter 13Building Mobile Apps Using XAML and Xamarin.Forms, discusses introducing you to taking C# mobile by building a cross-platform app for iOS and Android. The client-side mobile app will be created with Visual Studio for Mac using XAML and Xamarin.Forms.

Chapter 14Understanding .NET Core Internals and Measuring Performance, discusses the core concepts of .NET Core, including the compilation process, garbage collection, building highly-performant .NET Core applications utilizing multiple cores of the CPU, and publishing an application using a release build. We will also explore the benchmarking tool that is highly used for code optimization and provides results specific to in-memory objects.

Chapter 15Data Structures and Writing Optimized Code in C#, outlines the core concepts of data structures, the types of data structure, and their advantages and disadvantages, followed by the best possible scenarios to which each data structure is suited. We also learn about the Big O notation, which is one of the core topics to consider when writing code and helps developers check the quality of the code and performance. Lastly, we will look into some best practices and cover topics such as boxing and unboxing, string concatenation, exception handling, for and foreach, and delegates.

Chapter 16Designing Guidelines for .NET Core Application Performance, showcases some coding principles that make application code look clean and easy to understand. If the code is clean, it offers other developers a way to understand it completely and helps in many other ways. We will learn some basic design principles that are considered to be part of the core principles when designing applications. Principles such as KISS, YAGNI, DRY, Separation of Concerns, and SOLID are highly essential in software design, and caching and choosing the right data structure have a significant impact on performance, and can improve performance if they are properly used. Lastly, we will learn some best practices that should be considered when handling communication, resource management, and concurrency.

 

Chapter 17Memory Management Techniques in .NET Core, outlines the underlying process of how memory management is done in .NET. We will explore the debugging tool, which can be used by developers to investigate the object's memory allocation on the heap. We will also learn about memory fragmentation, finalizers, and how to implement a dispose pattern to clean up resources by implementing the IDisposable interface.

Chapter 18Microservices Architecture, looks at the most quickly evolving software architecture for developing highly performant and scalable applications for the cloud based on microservices. We will learn some of the core fundamentals of the microservices architecture, its benefits, and patterns and practices used when designing the architecture. We will discuss certain challenges faced when decomposing enterprise applications into the microservices architecture style and learn patterns such as API composition and CQRS in order to address them. Later in the chapter, we will develop a basic application in .NET Core and discuss the solution's structure and the components of microservices. Then we will develop identity and vendor services.

To Get the Most out of This Book

The readers should be equipped with the following configurations of the environment:

  1. Visual Studio 2017 on Windows 10
  2. Visual Studio for Mac on macOS
  3. Visual Studio Code on Windows 10 or macOS
  4. Visual Studio 2015/2017 Community Edition
  5. .NET Core

The best version of Windows to use is Microsoft Windows 10 because you will need this version to create Universal Windows Platform apps in Chapter 12Building Windows Apps Using XAML and Fluent Design. Earlier versions of Windows, such as 7 or 8.1, will work for the other chapters.

The best version of macOS to use is Sierra or High Sierra because you will need macOS to build iOS mobile apps in Chapter 13Building Mobile Apps Using XAML and Xamarin.Forms. Although you can use Visual Studio 2017 on Windows to write the code for iOS and Android mobile apps, you must have macOS and Xcode to compile them.

Download the Example Code Files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Csharp7-and-.NET-Designing-Modern-Cross-platform-Applications. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/Csharp7_and_dotNet_Design_Modern_Cross_Platform_Applications.pdf

 

Conventions Used

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We have statically imported the Console type so that we can simplify calls to its methods such as WriteLine."

A block of code is set as follows:

using System; 
 
namespace Packt.CS7 
{ 
   public class Person 
   { 
   } 
} 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<Project Sdk="Microsoft.NET.Sdk> 
 
  <PropertyGroup> 
    <OutputType>Exe</OutputType> 
      <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup> 
 
  <ItemGroup> 
    <ProjectReference
      Include="../PacktLibrary/PacktLibrary.csproj" /> 
  </ItemGroup> 
 
</Project> 

Any command-line input or output is written as follows:

cd PacktLibrary
dotnet new classlib
cd ..
cd PeopleApp
dotnet new console

 

 

 

 

 

 

Bold: New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "This rule is known as Banker's Rounding..."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in Touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.