Book Image

Learn C# Programming

By : Marius Bancila, Raffaele Rialdi, Ankit Sharma
5 (1)
Book Image

Learn C# Programming

5 (1)
By: Marius Bancila, Raffaele Rialdi, Ankit Sharma

Overview of this book

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.
Table of Contents (20 chapters)

Working with streams

A stream is a sequence of bytes that can be stored locally in memory, in a file, a pipe, remotely on the network, or other conceivable sources. .NET abstracts this concept with a class called Stream, which provides support for reading from and writing to a stream. On the other hand, the streams are conceptually grouped into three categories:

  • Backing store: These are streams that represent the source or the destination of a sequence of bytes. They are an endpoint for input or output data such as a file or network. Backing store streams work at the byte level. .NET provides classes such as FileStream, MemoryStream, and NetworkStream to implement backing stores.
  • Decorators: These are streams that read or write data from or to another stream, transforming it in some way. Like backing stores, they work with bytes. Decorators can be chained together. .NET provides decorator streams such as BufferedStream, CryptoStream, DeflateStream, and GZipStream.
  • Adapters...