Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition
C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition

C# 10 and .NET 6 – Modern Cross-Platform Development: Build apps, websites, and services with ASP.NET Core 6, Blazor, and EF Core 6 using Visual Studio 2022 and Visual Studio Code, Sixth Edition

By Mark J. Price
€7.99 €4.99
Book Nov 2021 826 pages 6th Edition
eBook
€7.99 €4.99
Print
€59.99
Subscription
€14.99 Monthly
eBook
€7.99 €4.99
Print
€59.99
Subscription
€14.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 9, 2021
Length 826 pages
Edition : 6th Edition
Language : English
ISBN-13 : 9781801077361
Vendor :
Microsoft
Category :
Languages :
Table of content icon View table of contents Preview book icon Preview Book

C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition

Hello, C#! Welcome, .NET!

In this first chapter, the goals are setting up your development environment, understanding the similarities and differences between modern .NET, .NET Core, .NET Framework, Mono, Xamarin, and .NET Standard, creating the simplest application possible with C# 10 and .NET 6 using various code editors, and then discovering good places to look for help.

The GitHub repository for this book has solutions using full application projects for all code tasks and notebooks when possible:

https://github.com/markjprice/cs10dotnet6

Simply press the . (dot) key or change .com to .dev in the link above to change the GitHub repository into a live editor using Visual Studio Code for the Web, as shown in Figure 1.1:

Figure 1.1: Visual Studio Code for the Web live editing the book's GitHub repository

This is great to run alongside your chosen code editor as you work through the book's coding tasks. You can compare your code to the solution code...

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 2022 for Windows
  • Visual Studio 2022 for Mac
  • Visual Studio Code for Windows, Mac, or Linux
  • GitHub Codespaces

Third parties have created their own C# code editors, for example, JetBrains Rider.

Choosing the appropriate tool and application type for learning

What is the best tool and application type for learning C# and .NET?

When learning, the best tool is one that helps you write code and configuration but does not hide what is really happening. IDEs provide graphical user interfaces that are friendly to use, but what are they doing for you underneath? A more basic code editor that is closer to the action while providing help to write your code is better while you are learning.

Having said that, you can make...

Understanding .NET

.NET 6, .NET Core, .NET Framework, and Xamarin are related and overlapping platforms for developers used to build applications and services. In this section, I'm going to introduce you to each of these .NET concepts.

Understanding .NET Framework

.NET Framework is a development platform that includes a Common Language Runtime (CLR), which manages the execution of code, and a Base Class Library (BCL), which provides a rich library of classes to build applications from.

Microsoft originally designed .NET Framework to have the possibility of being cross-platform, but Microsoft put their implementation effort into making it work best with Windows.

Since .NET Framework 4.5.2, it has been an official component of the Windows operating system. Components have the same support as their parent products, so 4.5.2 and later follow the life cycle policy of the Windows OS on which it is installed. .NET Framework is installed on over one billion computers...

Building console apps using Visual Studio 2022

The goal of this section is to showcase how to build a console app using Visual Studio 2022 for Windows.

If you do not have a Windows computer or you want to use Visual Studio Code, then you can skip this section since the code will be the same, just the tooling experience is different.

Managing multiple projects using Visual Studio 2022

Visual Studio 2022 has a concept named a solution that allows you to open and manage multiple projects simultaneously. We will use a solution to manage the two projects that you will create in this chapter.

Writing code using Visual Studio 2022

Let's get started writing code!

  1. Start Visual Studio 2022.
  2. In the Start window, click Create a new project.
  3. In the Create a new project dialog, enter console in the Search for templates box, and select Console App, making sure that you have chosen the C# project template rather than another language, such as F# or...

Building console apps using Visual Studio Code

The goal of this section is to showcase how to build a console app using Visual Studio Code.

If you never want to try Visual Studio Code or .NET Interactive Notebooks, then please feel free to skip this section and the next, and then continue with the Reviewing the folders and files for projects section.

Both the instructions and screenshots in this section are for Windows, but the same actions will work with Visual Studio Code on the macOS and Linux variants.

The main differences will be native command-line actions such as deleting a file: both the command and the path are likely to be different on Windows or macOS and Linux. Luckily, the dotnet command-line tool will be identical on all platforms.

Managing multiple projects using Visual Studio Code

Visual Studio Code has a concept named a workspace that allows you to open and manage multiple projects simultaneously. We will use a workspace to manage the two...

Exploring code using .NET Interactive Notebooks

.NET Interactive Notebooks makes writing code even easier than top-level programs. It requires Visual Studio Code, so if you did not install it earlier, please install it now.

Creating a notebook

First, we need to create a notebook:

  1. In Visual Studio Code, close any open workspaces or folders.
  2. Navigate to View | Command Palette.
  3. Type .net inter, and then select .NET Interactive: Create new blank notebook, as shown in Figure 1.13:

    Figure 1.13: Creating a new blank .NET notebook

  4. When prompted to select the file extension, choose Create as '.dib'.

    .dib is an experimental file format defined by Microsoft to avoid confusion and compatibility issues with the .ipynb format used by Python interactive notebooks. The file extension was historically only for Jupyter notebooks that can contain an interactive (I) mix of data, Python code (PY), and output in a notebook...

Reviewing the folders and files for projects

In this chapter, you created two projects named HelloCS and TopLevelProgram.

Visual Studio Code uses a workspace file to manage multiple projects. Visual Studio 2022 uses a solution file to manage multiple projects. You also created a .NET Interactive notebook.

The result is a folder structure and files that will be repeated in subsequent chapters, although with more than just two projects, as shown in Figure 1.18:

Figure 1.18: Folder structure and files for the two projects in this chapter

Understanding the common folders and files

Although .code-workspace and .sln files are different, the project folders and files such as HelloCS and TopLevelProgram are identical for Visual Studio 2022 and Visual Studio Code. This means that you can mix and match between both code editors if you like:

  • In Visual Studio 2022, with a solution open, navigate to File | Add Existing Project… to add a project file...

Making good use of the GitHub repository for this book

Git is a commonly used source code management system. GitHub is a company, website, and desktop application that makes it easier to manage Git. Microsoft purchased GitHub in 2018, so it will continue to get closer integration with Microsoft tools.

I created a GitHub repository for this book, and I use it for the following:

  • To store the solution code for the book that can be maintained after the print publication date.
  • To provide extra materials that extend the book, like errata fixes, small improvements, lists of useful links, and longer articles that cannot fit in the printed book.
  • To provide a place for readers to get in touch with me if they have issues with the book.

Raising issues with the book

If you get stuck following any of the instructions in this book, or if you spot a mistake in the text or the code in the solutions, please raise an issue in the GitHub repository:

    ...

Looking for help

This section is all about how to find quality information about programming on the web.

Reading Microsoft documentation

The definitive resource for getting help with Microsoft developer tools and platforms is Microsoft Docs, and you can find it at the following link: https://docs.microsoft.com/.

Getting help for the dotnet tool

At the command line, you can ask the dotnet tool for help with its commands:

  1. To open the official documentation in a browser window for the dotnet new command, enter the following at the command line or in the Visual Studio Code terminal:
    dotnet help new
    
  2. To get help output at the command line, use the -h or --help flag, as shown in the following command:
    dotnet new console -h
    
  3. You will see the following partial output:
    Console Application (C#)
    Author: Microsoft
    Description: A project for creating a command-line application that can run on .NET Core on Windows, Linux...

Practicing and exploring

Let's now test your knowledge and understanding by trying to answer some questions, getting some hands-on practice, and going into the topics covered throughout this chapter in greater detail.

Exercise 1.1 – Test your knowledge

Try to answer the following questions, remembering that although most answers can be found in this chapter, you should do some online research or code writing to answer others:

  1. Is Visual Studio 2022 better than Visual Studio Code?
  2. Is .NET 6 better than .NET Framework?
  3. What is .NET Standard and why is it still important?
  4. Why can a programmer use different languages, for example, C# and F#, to write applications that run on .NET?
  5. What is the name of the entry point method of a .NET console application and how should it be declared?
  6. What is a top-level program and how do you access any command-line arguments?
  7. What do you type at the prompt to build and execute C# source...

Summary

In this chapter, we:

  • Set up your development environment.
  • Discussed the similarities and differences between modern .NET, .NET Core, .NET Framework, Xamarin, and .NET Standard.
  • Used Visual Studio Code with the .NET SDK and Visual Studio 2022 for Windows to create some simple console applications.
  • Used .NET Interactive Notebooks to execute snippets of code for learning.
  • Learned how to download the solution code for this book from a GitHub repository.
  • And, most importantly, learned how to find help.

In the next chapter, you will learn how to "speak" C#.

Where to find the code solutions

You can download solutions for the step-by-step guided tasks and exercises from the GitHub repository at the following link: https://github.com/markjprice/cs10dotnet6.

Join our book’s Discord space

Join the book’s Discord workspace for a Ask me Anything session with the authors:

https://packt.link/SAcsharp10dotnet6...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Explore the newest additions to C# 10, the .NET 6 class library, and Entity Framework Core 6
  • Create professional websites and services with ASP.NET Core 6 and Blazor
  • Build cross-platform apps for Windows, macOS, Linux, iOS, and Android

Description

Extensively revised to accommodate all the latest features that come with C# 10 and .NET 6, this latest edition of our comprehensive guide will get you coding in C# with confidence. You’ll learn object-oriented programming, writing, testing, and debugging functions, implementing interfaces, and inheriting classes. The book covers the .NET APIs for performing tasks like managing and querying data, monitoring and improving performance, and working with the filesystem, async streams, and serialization. You’ll build and deploy cross-platform apps, such as websites and services using ASP.NET Core. Instead of distracting you with unnecessary application code, the first twelve chapters will teach you about C# language constructs and many of the .NET libraries through simple console applications. In later chapters, having mastered the basics, you’ll then build practical applications and services using ASP.NET Core, the Model-View-Controller (MVC) pattern, and Blazor.

What you will learn

Build rich web experiences using Blazor, Razor Pages, the Model-View-Controller (MVC) pattern, and other features of ASP.NET Core Build your own types with object-oriented programming Write, test, and debug functions Query and manipulate data using LINQ Integrate and update databases in your apps using Entity Framework Core, Microsoft SQL Server, and SQLite Build and consume powerful services using the latest technologies, including gRPC and GraphQL Build cross-platform apps using XAML

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 9, 2021
Length 826 pages
Edition : 6th Edition
Language : English
ISBN-13 : 9781801077361
Vendor :
Microsoft
Category :
Languages :

Table of Contents

20 Chapters
Preface Chevron down icon Chevron up icon
1. Hello, C#! Welcome, .NET! Chevron down icon Chevron up icon
2. Speaking C# Chevron down icon Chevron up icon
3. Controlling Flow, Converting Types, and Handling Exceptions Chevron down icon Chevron up icon
4. Writing, Debugging, and Testing Functions Chevron down icon Chevron up icon
5. Building Your Own Types with Object-Oriented Programming Chevron down icon Chevron up icon
6. Implementing Interfaces and Inheriting Classes Chevron down icon Chevron up icon
7. Packaging and Distributing .NET Types Chevron down icon Chevron up icon
8. Working with Common .NET Types Chevron down icon Chevron up icon
9. Working with Files, Streams, and Serialization Chevron down icon Chevron up icon
10. Working with Data Using Entity Framework Core Chevron down icon Chevron up icon
11. Querying and Manipulating Data Using LINQ Chevron down icon Chevron up icon
12. Improving Performance and Scalability Using Multitasking Chevron down icon Chevron up icon
13. Introducing Practical Applications of C# and .NET Chevron down icon Chevron up icon
14. Building Websites Using ASP.NET Core Razor Pages Chevron down icon Chevron up icon
15. Building Websites Using the Model-View-Controller Pattern Chevron down icon Chevron up icon
16. Building and Consuming Web Services Chevron down icon Chevron up icon
17. Building User Interfaces Using Blazor Chevron down icon Chevron up icon
18. Epilogue Chevron down icon Chevron up icon
19. Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.