Learn C# Programming
eBook - ePub

Learn C# Programming

A guide to building a solid foundation in C# language for writing efficient programs

Marius Bancila, Raffaele Rialdi, Ankit Sharma

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

Learn C# Programming

A guide to building a solid foundation in C# language for writing efficient programs

Marius Bancila, Raffaele Rialdi, Ankit Sharma

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Get started with C# and strengthen your knowledge of core programming concepts such as procedural, object-oriented, generic, functional, and asynchronous programming along with the latest features of C# 8

Key Features

  • Learn the fundamentals of C# with the help of easy-to-follow examples and explanations
  • Leverage the latest features of C# 8, including nullable reference types, pattern matching enhancements, and asynchronous streams
  • Explore object-oriented programming, functional programming, and multithreading concepts

Book Description

The C# programming language is often developers' primary choice for creating a wide range of applications for desktop, cloud, and mobile. In nearly two decades of its existence, C# has evolved from a general-purpose, object-oriented language to a multi-paradigm language with impressive features.

This book will take you through C# from the ground up in a step-by-step manner. You'll start with the building blocks of C#, which include basic data types, variables, strings, arrays, operators, control statements, and loops. Once comfortable with the basics, you'll then progress to learning object-oriented programming concepts such as classes and structures, objects, interfaces, and abstraction. Generics, functional programming, dynamic, and asynchronous programming are covered in detail. This book also takes you through regular expressions, reflection, memory management, pattern matching, exceptions, and many other advanced topics. As you advance, you'll explore the.NET Core 3 framework and learn how to use the dotnet command-line interface (CLI), consume NuGet packages, develop for Linux, and migrate apps built with.NET Framework. Finally, you'll understand how to run unit tests with the Microsoft unit testing frameworks available in Visual Studio.

By the end of this book, you'll be well-versed with the essentials of the C# language and be ready to start creating apps with it.

What you will learn

  • Get to grips with all the new features of C# 8
  • Discover how to use attributes and reflection to build extendable applications
  • Utilize LINQ to uniformly query various sources of data
  • Use files and streams and serialize data to JSON and XML
  • Write asynchronous code with the async-await pattern
  • Employ.NET Core tools to create, compile, and publish your applications
  • Create unit tests with Visual Studio and the Microsoft unit testing frameworks

Who this book is for

If you have little experience in coding or C# and want to learn the essentials of C# programming to develop powerful programming techniques, this book is for you. It will also help aspiring programmers to write scripts or programs to accomplish specific tasks.

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.
Learn C# Programming è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Learn C# Programming di Marius Bancila, Raffaele Rialdi, Ankit Sharma in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Informatica e Programmazione in C#. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2020
ISBN
9781789808445
Edizione
1
Argomento
Informatica

Chapter 1: Starting with the Building Blocks of C#

C# is one of the most widely used general-purpose programming languages. It is a multi-paradigm language that combines object-oriented, imperative, declarative, functional, generic, and dynamic programming. C# is one of the programming languages designed for the Common Language Infrastructure (CLI) platform, which is an open specification developed by Microsoft and standardized by the International Organization for Standardization (ISO) and European Computer Manufacturers Association (ECMA) that describes executable code and a runtime environment to be used on different computer platforms without being rewritten for specific architectures.
Over the years, C# has evolved with powerful features released version by version. The most recent version (at the time of writing) is C# 8, which has introduced several features to empower developers to be more productive. These include nullable reference types, ranges and indices, asynchronous streams, default implementations of interface members, recursive patterns, switch expressions, and many others. You will learn about these features in detail in Chapter 15, New Features of C# 8.
In this chapter, we will introduce you to the language, the .NET Framework, and the basic concepts around them. We have structured the contents of this chapter as follows:
  • Learning the history of C#
  • Understanding the CLI
  • Knowing the .NET family of frameworks
  • Assemblies in .NET
  • Understanding the basic structure of a C# program
At the end of this chapter, you will learn how to write a Hello World! program in C#.

The history of C#

C# development started at Microsoft in the late 1990s by a team led by Anders Hejlsberg. Initially, it was called Cool, but when the .NET project was first publicly announced in the summer of 2002, the language was renamed C#. The use of the sharp suffix was intended to denote that the language is an increment of C++, which, along with Java, Delphi, and Smalltalk, acted as an inspiration for the CLI and the C# language design.
The first version of C#, called 1.0, was made available in 2002 bundled with .NET Framework 1.0 and Visual Studio .NET 2002. Since then, major and minor increments of the language have been released together with new versions of .NET Framework and Visual Studio. The following table lists all of the versions and some of the key features for each of these releases:
The latest version of the language at the time of writing, 8.0, is being released with .NET Core 3.0. Although most features will also work in projects targeting .NET Framework, some of them will not because they require changes in the runtime, which is something Microsoft will no longer do as .NET Framework is being deprecated in favor of .NET Core.
Now that you have an overview of the evolution of the C# language over time, let's start looking at the platforms that the language is targeting.

Understanding the CLI

The CLI is a specification that describes how a runtime environment can be used on different computer platforms without being rewritten for specific architectures. It is developed by Microsoft and standardized by ECMA and ISO. The following diagram shows the high-level functionality of the CLI:
Figure 1.1 – Diagram of the high-level functionality of the CLI
Figure 1.1 – Diagram of the high-level functionality of the CLI
The CLI enables programs written in a variety of programming languages (that are CLS-compliant) to be executed on any operating system and with a single runtime. The CLI specifies a common language, called the Common Language Specification (CLS), a common set of data types that any language must support, called the Common Type System, and other things such as how exceptions are handled and how the state is managed. The various aspects specified by the CLI are described in more detail in the following sections.
Information box
Because of the limited scope of this chapter, a deep dive into the specification is not possible. If you want more information about the CLI, you can visit the ISO site at https://www.iso.org/standard/58046.html.
There are several implementations of the CLI and among these, the most important ones are .NET Framework, .NET Core, and Mono/Xamarin.

Common Type System (CTS)

The CTS is a component of the CLI that describes how type definitions and values are represented and memory is intended to facilitate the sharing of data between programming languages. The following are some of the characteristics and functions of the CTS:
  • It enables cross-platform integration, type safety, and high-performance code execution.
  • It provides an object-oriented model that supports the complete implementation of many programming languages.
  • It provides rules for languages to ensure that objects and data types of objects written in different programming languages can interact with each other.
  • It defines rules for type visibility and access to members.
  • It defines rules for type inheritance, virtual methods, and object lifetime.
The CTS supports two categories of types:
  • Value types: These contain their data directly and have copy semantics, which means when an object of such a type is copied its data is copied.
  • Reference types: These contain references to the memory address where the data is stored. When an object of a reference type is copied, the reference is copied and not the data it points to.
Although it is an implementation detail, value types are usually stored on the stack and reference types on the heap. Conversion between value types and a reference type is possible and known as boxing, while the other way around is called unboxing. These concepts will be explained in further detail in the next chapter.

Common Language Specification (CLS)

The CLS comprises a set of rules that any language that targets the CLI needs to adhere to, to be able to interoperate with other CLS-compliant languages. CLS rules fall into the broader rules of the CTS and therefore it can be said that the CLS is a subset of CTS. All of the rules of CTS apply to the CLS unless the CLS rules are stricter. Language constructs that make it impossible to easily verify the type safety of the code were excluded from the CLS so that all languages that work with the CLS can produce verifiable code.
The relationship between the CTS and CLS as well as the programming languages targeting the CLI is conceptually shown in the following diagram:
Figure 1.2 – A diagram showing the conceptual relationship between the CTS and CLS and the programming languages that target the CLI
Figure 1.2 – A diagram showing the conceptual relationship between the CTS and CLS and the programming languages that tar...

Indice dei contenuti