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

  1. 636 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et 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

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

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.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Learn C# Programming est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Learn C# Programming par Marius Bancila, Raffaele Rialdi, Ankit Sharma en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming in C#. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2020
ISBN
9781789808445
Édition
1

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

Table des matiĂšres

  1. Learn C# Programming
  2. Why subscribe?
  3. Preface
  4. Chapter 1: Starting with the Building Blocks of C#
  5. Chapter 2: Data Types and Operators
  6. Chapter 3: Control Statements and Exceptions
  7. Chapter 4: Understanding the Various User-Defined Types
  8. Chapter 5: Object-Oriented Programming in C#
  9. Chapter 6: Generics
  10. Chapter 7: Collections
  11. Chapter 8: Advanced Topics
  12. Chapter 9: Resource Management
  13. Chapter 10: Lambdas, LINQ, and Functional Programming
  14. Chapter 11: Reflection and Dynamic Programming
  15. Chapter 12: Multithreading and Asynchronous Programming
  16. Chapter 13: Files, Streams, and Serialization
  17. Chapter 14: Error Handling
  18. Chapter 15: New Features of C# 8
  19. Chapter 16: C# in Action with .NET Core 3
  20. Chapter 17: Unit Testing
  21. Assessments
  22. Other Books You May Enjoy