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

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

Mark J. Price

Compartir libro
  1. 824 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

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

Mark J. Price

Detalles del libro
Vista previa del libro
Índice
Citas

Información del 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.

]]>

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es C# 10 and .NET 6 – Modern Cross-Platform Development un PDF/ePUB en línea?
Sí, puedes acceder a C# 10 and .NET 6 – Modern Cross-Platform Development de Mark J. Price en formato PDF o ePUB, así como a otros libros populares de Computer Science y Programming in C#. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
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...

Índice