Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals
C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals

C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals: Start building websites and services with ASP.NET Core 9, Blazor, and EF Core 9 , Ninth Edition

Arrow left icon
Profile Icon Mark J. Price
Arrow right icon
$19.99 per month
Paperback Nov 2024 828 pages 9th Edition
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Mark J. Price
Arrow right icon
$19.99 per month
Paperback Nov 2024 828 pages 9th Edition
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$24.99 $35.99
Paperback
$44.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals

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 – Online material

Online material can be extra content written by me for this book, or it can be references to content created by Microsoft or third parties.

Current versions of .NET

You can check what the latest version of .NET is for various platforms and what is officially supported at the following link: https://versionsof.net.

If you need to know more about support for the legacy .NET Framework, you can read about it at the following link: https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-framework.

Upgrade to a new .NET version

.NET releases new versions annually. Some developers begin upgrading as soon as a new version drops, while others prefer to wait until their current version reaches end-of-support. Upgrading involves...

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 in an online article.
  • Used Visual Studio and VS Code with the .NET SDK CLI to create a couple of simple console apps, grouped in a solution.
  • Learned how to download the solution code for this book from its GitHub repository.
  • Learned how to find help. This could be in the traditional way, by using help command switches, documentation, and articles, or the modern way, by having a conversation with a coding expert AI or using an AI-based tool to perform "grunt work."

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

Discovering your C# compiler version

The .NET language compiler for C# and Visual Basic, also known as Roslyn, along with a separate compiler for F#, is distributed as part of the .NET SDK. To use a specific version of C#, you must have at least that version of the .NET SDK installed, as shown in Table 2.2:

.NET SDK

Roslyn compiler

Default C# language

1.0.4

2.0–2.2

7.0

1.1.4

2.3–2.4

7.1

2.1.2

2.6–2.7

7.2

2.1.200

...

Understanding C# grammar and vocabulary

Let’s start by looking at the basics of the grammar and vocabulary of C#. Throughout this chapter, you will create multiple console apps, with each one showing related features of the C# language.

Understanding C# grammar

The grammar of C# includes statements and blocks. To document your code, you can use comments.

Good Practice: Comments should not be the only way that you document your code. Choosing sensible names for variables and functions, writing unit tests, and creating actual documents are other ways to document your code.

Statements

In English, we indicate the end of a sentence with a period. A sentence can be composed of multiple words and phrases, with the order of words being part of the grammar. For example, in English, we say “the black cat.”

The adjective, black, comes before the noun, cat. However, French grammar has a different order; the adjective comes after the noun...

Working with variables

All applications process data. Data comes in, data is processed, and then data goes out.

Data usually comes into our program from files, databases, or user input, and it can be put temporarily into variables, which will be stored in the memory of the running program. When the program ends, the data in memory is lost. Data is usually output to files and databases, or to the screen or a printer. When using variables, you should think about, firstly, how much space the variable takes up in the memory, and, secondly, how fast it can be processed.

We control this by picking an appropriate type. You can think of simple common types such as int and double as being different-sized storage boxes, where a smaller box would take less memory but may not be as fast at being processed; for example, adding 16-bit numbers might not be processed as quickly as adding 64-bit numbers on a 64-bit operating system. Some of these boxes may be stacked close by, and some may...

Exploring more about console apps

We have already created and used basic console apps, but we’re now at a stage where we should delve into them more deeply.

Console apps are text-based and are run at the command prompt. They typically perform simple tasks that need to be scripted, such as compiling a file or encrypting a section of a configuration file.

Equally, they can also have arguments passed to them to control their behavior.

An example of this would be to create a new console app using the F# language with a specified name instead of using the name of the current folder, as shown in the following command:

dotnet new console -lang "F#" --name "ExploringConsole"

Displaying output to the user

The two most common tasks that a console app performs are writing and reading data. We have already used the WriteLine method to output, but if we didn’t want a carriage return at the end of a line, for example, if we later wanted...

Practicing and exploring

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

Exercise 2.1 – Online material

Online materials can be extra content written by me for this book, or it can be references to content created by Microsoft or third parties.

Understanding async and await

C# 5 introduced two C# keywords when working with the Task type that enable easy multithreading. You can read about them and see a code example at the following link:

https://github.com/markjprice/cs13net9/blob/main/docs/ch02-async-await.md

Explore Spectre

No, not the villainous organization from the James Bond films! Spectre is a package that enhances console apps. You can read about it at the following link: https://spectreconsole.net/.

Exercise 2.2 – Practice exercises

Practice exercises go deeper into the topics for this chapter.

Explore...

Summary

In this chapter, you learned how to:

  • Declare variables with a specified or inferred type.
  • Use some of the built-in types for numbers, text, and Booleans.
  • Choose between number types.
  • Control output formatting in console apps.

In the next chapter, you will learn about operators, branching, looping, converting between types, and how to handle exceptions.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Explore the newest additions to C# 13, the .NET 9 class libraries, and Entity Framework Core 9
  • Build professional websites and services with ASP.NET Core 9 and Blazor
  • Enhance your skills with step-by-step code examples and best practices tips

Description

This Packt bestseller continues to be the definitive guide to modern cross-platform development. The 9th edition of C# 13 and .NET 9 – Modern Cross-Platform Development Fundamentals has been updated to cover the latest features and improvements in .NET 9 and C# 13. You'll start by mastering object-oriented programming, learning how to write, test, and debug functions, and implementing interfaces. You'll then dive into .NET APIs for data management, filesystem operations, and serialization. This latest edition integrates .NET 9 enhancements into its examples: faster exceptions and new LINQ methods. New ASP.NET Core 9 features include optimized static assets, built-in OpenAPI document generation, and the HybridCache. Practical examples, such as building websites and services with ASP.NET Core, have been refreshed to utilize the latest .NET 9 features. The book also introduces Blazor, with its new unified hosting model for unparalleled code reusability. With these updates, you'll learn how to build robust applications and services efficiently and effectively. By the end of this book, you'll have the knowledge and confidence to create professional and high-performance web applications using the latest technologies in C# 13 and .NET 9.

Who is this book for?

This book is aimed at beginner to intermediate-level C# and .NET developers. While prior exposure to C# or .NET is not a prerequisite, a general understanding of programming concepts will be beneficial. If you want to learn more technologies for building modern .NET projects like gRPC, SignalR, and .NET MAUI, read Mark's Apps and Services with .NET 8 book next; and if you aim to become a professional .NET developer quickly or mainly work on team projects, read his other book, Tools and Skills for .NET 8.

What you will learn

  • Discover the new features of .NET 9, including more flexible params and new LINQ like CountBy and Index
  • Leverage the new ASP.NET Core 9 features for optimized static assets, OpenAPI document generation, and HybridCache
  • Utilize the native AOT publish capability for faster startup and reduced memory footprint
  • Build rich web user interface experiences using Blazor in ASP.NET Core 9
  • Integrate and update databases in your applications using Entity Framework Core 9 models
  • Query and manipulate data using LINQ
  • Build powerful services using Minimal APIs

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 12, 2024
Length: 828 pages
Edition : 9th
Language : English
ISBN-13 : 9781835881224
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 12, 2024
Length: 828 pages
Edition : 9th
Language : English
ISBN-13 : 9781835881224
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
Banner background image

Table of Contents

17 Chapters
Hello, C#! Welcome, .NET! Chevron down icon Chevron up icon
Speaking C# Chevron down icon Chevron up icon
Controlling Flow, Converting Types, and Handling Exceptions Chevron down icon Chevron up icon
Writing, Debugging, and Testing Functions Chevron down icon Chevron up icon
Building Your Own Types with Object-Oriented Programming Chevron down icon Chevron up icon
Implementing Interfaces and Inheriting Classes Chevron down icon Chevron up icon
Packaging and Distributing .NET Types Chevron down icon Chevron up icon
Working with Common .NET Types Chevron down icon Chevron up icon
Working with Files, Streams, and Serialization Chevron down icon Chevron up icon
Working with Data Using Entity Framework Core Chevron down icon Chevron up icon
Querying and Manipulating Data Using LINQ Chevron down icon Chevron up icon
Introducing Modern Web Development Using .NET Chevron down icon Chevron up icon
Building Websites Using ASP.NET Core Chevron down icon Chevron up icon
Building Interactive Web Components Using Blazor Chevron down icon Chevron up icon
Building and Consuming Web Services Chevron down icon Chevron up icon
Epilogue Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.