Preface
C# is a general-purpose, multi-paradigm programming language that combines object-oriented, imperative, generic, functional, declarative, and dynamic programming. Soon after its release, C# became one of the top choices for developers for writing a large variety of types of applications. Although it is not the only language targeting the CLI (the others include VB.NET and F#), it is the primary choice for writing .NET applications for desktop, web, cloud, and mobile platforms.
Over the years, the language has evolved gradually but steadily. Although initially it was an object-oriented programming language, new versions have opened up the language to new paradigms such as generic, functional, and dynamic programming. New language features and more concise syntax have also been added regularly. With its release as an open source project of the .NET Compiler Platform, also known as Roslyn, which is a set of compilers and code analysis APIs for C# and VB.NET, the language has entered a new open era with the community deeply involved in the development of the language.
The current version of the language is known as C# 8. This was released in September 2019 for .NET Core 3.0 and requires Visual Studio 2019 16.3 or a newer version. C# 8 can also be used with .NET Framework, although not all features are available. That is because they required runtime changes, which was something Microsoft did not want to do due to its intent to no longer invest in .NET Framework (other than long-time support) and turn .NET Core into the one framework used to target all platforms and types of applications. This framework will be known simply as .NET.
This book is designed to help you learn the language from scratch and eventually master all its multi-paradigm programming aspects. We start with the very basics: data types, statements, and other building blocks. We then continue with object-oriented concepts such as classes, interfaces, inheritance, and polymorphism. We cover generics, functional programming and LINQ, reflection and dynamic programming, and more advanced topics, such as resource management, pattern matching, concurrency and asynchronous programming, error handling, and serialization. Toward the end of the book, we give special attention to the new features introduced in C# 8. Last, but not least, we discuss unit testing and how you can write unit tests for your C# code. At the end of each chapter, we provide you with a set of questions to help you assess what you learned in that chapter.
The book contains many code snippets that are designed to help you easily understand and learn all the language features. All of them are available in the source code that accompanies the book. You will need either Visual Studio or Visual Studio Code to try them. Alternatively, you can use an online compiler, the primary choice in this case being https://sharplab.io/.