Book Image

C# 9 and .NET 5 – Modern Cross-Platform Development - Fifth Edition

By : Mark J. Price
Book Image

C# 9 and .NET 5 – Modern Cross-Platform Development - Fifth Edition

By: Mark J. Price

Overview of this book

In C# 9 and .NET 5 – Modern Cross-Platform Development, Fifth 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 a new chapter on the Microsoft Blazor framework. The book’s first part teaches the fundamentals of C#, including object-oriented programming and new C# 9 features such as top-level programs, target-typed new object instantiation, and immutable types using the record keyword. Part 2 covers the .NET APIs, for performing tasks like managing and querying data, monitoring and improving performance, and working with the file system, async streams, serialization, and encryption. Part 3 provides examples of cross-platform apps you can build and deploy, such as websites and services using ASP.NET Core or mobile apps using Xamarin.Forms. The best type of application for learning the C# language constructs and many of the .NET libraries is one that does not distract with unnecessary application code. For that reason, the C# and .NET topics covered in Chapters 1 to 13 feature console applications. In Chapters 14 to 20, having mastered the basics of the language and libraries, you will build practical applications using ASP.NET Core, Model-View-Controller (MVC), and Blazor. By the end of the book, you will have acquired the understanding and skills you need to use C# 9 and .NET 5 to create websites, services, and mobile apps.
Table of Contents (23 chapters)
22
Index

Practicing and exploring

Test your knowledge and understanding by answering some questions, get some hands-on practice, and explore the topics covered in this chapter with deeper research.

Exercise 2.1 – Test your knowledge

To get the best answer to some of these questions, you will need to do your own research. I want you to "think outside the book" so I have deliberately not provided all the answers in the book.

I want to encourage you to get in the good habit of looking for help elsewhere, following the principle of "teach a person to fish."

What type would you choose for the following "numbers"?

  1. A person's telephone number
  2. A person's height
  3. A person's age
  4. A person's salary
  5. A book's ISBN
  6. A book's price
  7. A book's shipping weight
  8. A country's population
  9. The number of stars in the universe
  10. The number of employees in each of the small or medium businesses in the United Kingdom (up to about 50,000 employees per business)

Exercise 2.2 – Practice number sizes and ranges

Create a console application project named Exercise02 that outputs the number of bytes in memory that each of the following number types uses, and the minimum and maximum values they can have: sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and decimal.

More Information: You can always read the documentation, available at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting for Composite Formatting to learn how to align text in a console application.

The result of running your console application should look something like the following screenshot:

A screenshot of a cell phone  Description automatically generated

Figure 2.10: The result of the console application

Exercise 2.3 – Explore topics

Use the following links to read more about the topics covered in this chapter:

  • C# Keywords: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/index
  • Main() and command-line arguments (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/
  • Types (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/
  • Statements, Expressions, and Operators (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/
  • Strings (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/
  • Nullable Types (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/
  • Nullable reference types: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references
  • Console Class: https://docs.microsoft.com/en-us/dotnet/api/system.console