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

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

Mark J. Price

Condividi libro
  1. 824 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

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

Mark J. Price

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

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.

]]>

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
C# 10 and .NET 6 – Modern Cross-Platform Development è disponibile online in formato PDF/ePub?
Sì, puoi accedere a C# 10 and .NET 6 – Modern Cross-Platform Development di Mark J. Price in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming in C#. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
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...

Indice dei contenuti