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

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

Mark J. Price

Buch teilen
  1. 824 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

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

Mark J. Price

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

]]>

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist C# 10 and .NET 6 – Modern Cross-Platform Development als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu C# 10 and .NET 6 – Modern Cross-Platform Development von Mark J. Price im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming in C#. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

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

Inhaltsverzeichnis