Book Image

C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals - Eighth Edition

By : Mark J. Price
4.6 (14)
Book Image

C# 12 and .NET 8 – Modern Cross-Platform Development Fundamentals - Eighth Edition

4.6 (14)
By: Mark J. Price

Overview of this book

This latest edition of the bestselling Packt series will give you a solid foundation to start building projects using modern C# and .NET with confidence. You'll learn about object-oriented programming; writing, testing, and debugging functions; and implementing interfaces. You'll take on .NET APIs for managing and querying data, working with the fi lesystem, and serialization. As you progress, you'll explore examples of cross-platform projects you can build and deploy, such as websites and services using ASP.NET Core. This latest edition integrates .NET 8 enhancements into its examples: type aliasing and primary constructors for concise and expressive code. You'll handle errors robustly through the new built-in guard clauses and explore a simplified implementation of caching in ASP.NET Core 8. If that's not enough, you'll also see how native ahead-of-time (AOT) compiler publish lets web services reduce memory use and run faster. You'll work with the seamless new HTTP editor in Visual Studio 2022 to enhance the testing and debugging process. You'll even get introduced to Blazor Full Stack with its new unified hosting model for unparalleled web development flexibility.
Table of Contents (18 chapters)

Working with text

One of the other most common types of data for variables is text. The most common types in .NET for working with text are shown in Table 8.2:

Namespace Type Description
System Char Storage for a single text character
System String Storage for multiple text characters
System.Text StringBuilder Efficiently manipulates strings
System.Text.RegularExpressions Regex Efficiently pattern-matches strings
Table 8.2: Common .NET types for working with text

Getting the length of a string

Let's explore some common tasks when working with text; for example, sometimes you need to find out the length of a piece of text stored in a string variable:

  1. Use your preferred code editor to add a new Console App / console project named WorkingWithText to the Chapter08 solution.
  2. In the WorkingWithText project, in Program.cs, delete the existing statements and then add statements to define a variable to store the name of the city London, and then write its name and length to...