Book Image

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development - Fourth Edition

By : Mark J. Price
Book Image

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development - Fourth Edition

By: Mark J. Price

Overview of this book

In C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development, Fourth Edition, expert teacher Mark J. Price gives you everything you need to start programming C# applications. This latest edition uses the popular Visual Studio Code editor to work across all major operating systems. It is fully updated and expanded with new chapters on Content Management Systems (CMS) and machine learning with ML.NET. The book covers all the topics you need. Part 1 teaches the fundamentals of C#, including object-oriented programming, and new C# 8.0 features such as nullable reference types, simplified switch pattern matching, and default interface methods. Part 2 covers the .NET Standard APIs, such as managing and querying data, monitoring and improving performance, working with the filesystem, async streams, serialization, and encryption. Part 3 provides examples of cross-platform applications you can build and deploy, such as web apps using ASP.NET Core or mobile apps using Xamarin.Forms. The book introduces three technologies for building Windows desktop applications including Windows Forms, Windows Presentation Foundation (WPF), and Universal Windows Platform (UWP) apps, as well as web applications, web services, and mobile apps.
Table of Contents (21 chapters)

Setting up your development environment

Before you start programming, you'll need a code editor for C#. Microsoft has a family of code editors and Integrated Development Environments (IDEs), which include:

  • Visual Studio Code
  • Visual Studio 2019
  • Visual Studio 2019 for Mac

Using Visual Studio Code for cross-platform development

The most modern and lightweight code editor to choose, and the only one from Microsoft that is cross-platform, is Microsoft Visual Studio Code. It is able to run on all common operating systems, including Windows, macOS, and many varieties of Linux, including Red Hat Enterprise Linux (RHEL) and Ubuntu.

Visual Studio Code is a good choice for modern cross-platform development because it has an extensive and growing set of extensions to support many languages beyond C#, and being cross-platform and lightweight it can be installed on all platforms that your apps will be deployed to for quick bug fixes and so on.

Using Visual Studio Code means a developer can use a cross-platform code editor to developer cross-platform apps. Therefore, I have chosen to use Visual Studio Code for all but the last two chapters for this book, because they need special features not available in Visual Studio Code for building Windows and mobile apps.

More Information: You can read about Microsoft's plans for Visual Studio Code at the following link:

If you prefer to use Visual Studio 2019 or Visual Studio for Mac instead of Visual Studio Code, then of course you can, but I will assume that you are already familiar with how to use them and so I will not give step-by-step instructions for using them in this book.

More Information: You can read a comparison of Visual Studio Code and Visual Studio 2019 at the following link:

Using Visual Studio 2019 for Windows app development

Microsoft Visual Studio 2019 only runs on Windows, version 7 SP1 or later. You must run it on Windows 10 to create Universal Windows Platform (UWP) apps. It is the only Microsoft developer tool that can create Windows apps, so we will use it in Chapter 20, Building Windows Desktop Apps.

Using Visual Studio for Mac for mobile development

To create apps for the Apple operating systems like iOS to run on devices like iPhone and iPad, you must have Xcode, but that tool only runs on macOS. Although you can use Visual Studio 2019 on Windows with its Xamarin extensions to write a cross-platform mobile app, you still need macOS and Xcode to compile it.

So, we will use Visual Studio 2019 for Mac on macOS in Chapter 21, Building Cross-Platform Mobile Apps Using Xamarin.Forms.

Recommended tools for chapters

To help you to set up the best environment to use in this book, the following table summarizes which tools and operating systems I recommend be used for each of the chapters in this book:

Chapters Tool Operating systems

Chapters 1 to 19

Visual Studio Code

Windows, macOS, Linux

Chapter 20

Visual Studio 2019

Windows 10

Chapter 21

Visual Studio 2019 for Mac


To write this book, I used my MacBook Pro and the following listed software:

  • Visual Studio Code on macOS as my primary code editor.
  • Visual Studio Code on Windows 10 in a virtual machine to test OS-specific behavior like working with the filesystem.
  • Visual Studio 2019 on Windows 10 in a virtual machine to build Windows apps.
  • Visual Studio 2019 for Mac on macOS to build mobile apps.

More Information: Google and Amazon are supporters of Visual Studio Code, as you can read at the following link:

Deploying cross-platform

Your choice of code editor and operating system for development does not limit where your code gets deployed.

.NET Core 3.0 supports the following platforms for deployment:

  • Windows: Windows 7 SP1, or later. Windows 10 version 1607, or later. Windows Server 2012 R2 SP1, or later. Nano Server version 1803, or later.
  • Mac: macOS High Sierra (version 10.13), or later.
  • Linux: RHEL 6, or later. RHEL, CentOS, Oracle Linux version 7, or later. Ubuntu 16.04, or later. Fedora 29, or later. Debian 9, or later. openSUSE 15, or later.

More Information: You can read the official list of supported operating systems at the following link:

Understanding Microsoft Visual Studio Code versions

Microsoft releases a new feature version of Visual Studio Code (almost) every month and bug fix versions more frequently. For example:

  • Version 1.38, August 2019 feature release.
  • Version 1.38.1, August 2019 bug fix release.

More Information: You can read about the latest versions at the following link:

The version used in this book is 1.38.1 released on 11 September 2019, but the version of Microsoft Visual Studio Code is less important than the version of the C# for Visual Studio Code extension that you will install later.

While the C# extension is not required, it provides IntelliSense as you type, code navigation, and debugging features, so it's something that's very handy to install. To support C# 8.0, you should install C# extension version 1.21.3 or later.

In this book, I will show keyboard shortcuts and screenshots of Visual Studio Code using the macOS version. Visual Studio Code on Windows and variants of Linux are practically identical, although keyboard shortcuts are likely different.

Some common keyboard shortcuts that we will use are shown in the following table:

Action macOS Windows

Show Command Palette

Cmd + Shift + P,


Ctrl + Shift + P,


Go To Definition



Go Back

Ctrl + -

Alt +

Go Forward

Ctrl + Shift + -

Alt +

Show Terminal

Ctrl + ` (backtick)

Ctrl + ' (quote)

New Terminal

Ctrl + Shift + ` (backtick)

Ctrl + Shift + ' (quote)

Toggle Line Comment

Ctrl + /

Ctrl + /

Toggle Block Comment

Shift + Option + A

Shift + Alt + A

I recommend that you download a PDF of keyboard shortcuts for your operating system from the following list:

  • Windows:
  • macOS:
  • Linux:

More Information: You can learn about the default key bindings for Visual Studio Code and how to customize them at the following link:

Visual Studio Code has rapidly improved over the past couple of years and has pleasantly surprised Microsoft with its popularity. If you are brave and like to live on the bleeding edge, then there is an Insiders edition, which is a daily build of the next version.

Downloading and installing Visual Studio Code

Now you are ready to download and install Visual Studio Code, its C# extension, and the .NET Core 3.0 SDK.

  1. Download and install either the Stable build or the Insiders edition of Visual Studio Code from the following link:
  2. Download and install the .NET Core SDK from the following link:
  3. To install the C# extension, you must first launch the Visual Studio Code application.
  4. In Visual Studio Code, click the Extensions icon or navigate to ViewExtensions.
  5. C# is one of the most popular extensions available, so you should see it at the top of the list, or you can enter C# in the search box, as shown in the following screenshot:
  1. Click Install and wait for supporting packages to download and install.

More Information: You can read more about Visual Studio Code support for C# at the following link:

Installing other extensions

In later chapters of this book, you will use more extensions. If you want to install them now, all the extensions that we will use are shown in the following table:

Extension Description

C# for Visual Studio Code (powered by OmniSharp)


C# editing support, including syntax highlighting, IntelliSense, Go to Definition, Find All References, debugging support for .NET Core (CoreCLR), and support for project.json and csproj projects on Windows, macOS, and Linux.

C# XML Documentation Comments k--kato.docomment

Generate XML documentation comments for Visual Studio Code.

C# Extensions


Add C# class, add C# interface, add fields and properties from constructors, add constructor from properties.

REST Client

Send an HTTP request and view the response directly in Visual Studio Code.

ILSpy .NET Decompiler


Decompile MSIL assemblies – support for .NET Framework, .NET Core, and .NET Standard.



Easily inspect the results of your code. It works similarly to standalone tools like LinqPad and RoslynPad.