C# 10 and .NET 6 – Modern Cross-Platform Development
eBook - ePub

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

Mark J. Price

Share book
  1. 824 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

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

Mark J. Price

Book details
Book preview
Table of contents
Citations

About This Book

Publisher's Note: Microsoft will stop supporting.NET 6 from November 2024. The newer 8th edition of the book is available that covers.NET 8 (end-of-life November 2026) with C# 12 and EF Core 8.Purchase of the print or Kindle book includes a free PDF eBook

Key Features

  • 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

Book 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

Who this book is for

Designed for both beginners and C# and.NET programmers who have worked with C# in the past and want to catch up with the changes made in the past few years, this book doesn't need you to have any C# or.NET experience. However, you should have a general understanding of programming before you jump in.

]]>

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is C# 10 and .NET 6 – Modern Cross-Platform Development an online PDF/ePUB?
Yes, you can access C# 10 and .NET 6 – Modern Cross-Platform Development by Mark J. Price in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in C#. We have over one million books available in our catalogue for you to explore.

Information

Year
2021
ISBN
9781801076968

06

Implementing Interfaces and Inheriting Classes

This chapter is about deriving new types from existing ones using object-oriented programming (OOP). You will learn about defining operators and local functions for performing simple actions and delegates and events for exchanging messages between types. You will implement interfaces for common functionality. You will learn about generics and the difference between reference and value types. You will create a derived class to inherit from a base class to reuse functionality, override an inherited type member, and use polymorphism. Finally, you will learn how to create extension methods and how to cast between classes in an inheritance hierarchy.
This chapter covers the following topics:
  • Setting up a class library and console application
  • More about methods
  • Raising and handling events
  • Making types safely reusable with generics
  • Implementing interfaces
  • Managing memory with reference and value types
  • Working with null values
  • Inheriting from classes
  • Casting within inheritance hierarchies
  • Inheriting and extending .NET types
  • Using an analyzer to write better code

Setting up a class library and console application

We will start by defining a workspace/solution with two projects like the one created in Chapter 5, Building Your Own Types with Object-Oriented Programming. Even if you completed all the exercises in that chapter, follow the instructions below because we will use C# 10 features in the class library, so it needs to target .NET 6.0 rather than .NET Standard 2.0:
  1. Use your preferred coding tool to create a new workspace/solution named Chapter06.
  2. Add a class library project, as defined in the following list:
    1. Project template: Class Library / classlib
    2. Workspace/solution file and folder: Chapter06
    3. Project file and folder: PacktLibrary
  3. Add a console app project, as defined in the following list:
    1. Project template: Console Application / console
    2. Workspace/solution file and folder: Chapter06
    3. Project file and folder: PeopleApp
  4. In the PacktLibrary project, rename the file named Class1.cs to Person.cs.
  5. Modify the Person.cs file contents, as shown in the following code:
    using static System.Console; namespace Packt.Shared; public class Person : object { // fields public string? Name; // ? allows null public DateTime DateOfBirth; public List<Person> Children = new(); // C# 9 or later // methods public void WriteToConsole() { WriteLine($"{Name} was born on a {DateOfBirth:dddd}."); } } 
  6. In the PeopleApp project, add a project reference to PacktLibrary, as shown highlighted in the following markup:
    <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup>  <ItemGroup>  <ProjectReference  Include="..\PacktLibrary\PacktLibrary.csproj" />  </ItemGroup> </Project> 
  7. Build the PeopleApp project and note the output indicating that both projects have been built successfully.

More about methods

We might want two instances of Person to be able to procreate. We can implement this by writing methods. Instance methods are actions that an object does to itself; static methods are actions the type does.
Which you choose depends on what makes the most sense for the action.
Go...

Table of contents