The chapter that opens the book, as it is printed: how the volume is made, who it is for, what you need.
Before you begin
Preface
A program with windows, which runs the same way on Windows, macOS and Linux, written in a single language: that is what this series teaches you to build. The language is C#, on .NET 10; the windows are drawn by Avalonia, an open library that draws everything by itself, and so behaves the same way everywhere. Almost everything you find about Avalonia describes the windows in XAML, a markup language; here instead everything is C#, and the compiler checks every line. The title of the series, Avalonia Code Only, comes from this.
To write a window in code you first have to know the code. This first volume is all C#: no windows, only console programs, the ones you use to learn a language because they show you straight away what happens. It starts from the installation and gets as far as threads, Task and await, measured in real programs. The windows begin in Volume 2, which starts exactly where this one ends.
The series has ten volumes:
- The C# language: types, objects, generics, exceptions, files, threads,
Taskandasync. This book. - Desktop interfaces: Avalonia in code, the controls, the themes, the architectures and the threads of the interface.
- 2D graphics: drawing and animation with Avalonia.
- Advanced 2D graphics: Skia, Direct2D, images.
- 3D graphics: 3D from scratch with OpenGL.
- Advanced 3D graphics: Vulkan and Direct3D.
- Audio.
- Video.
- Devices, data and network.
- System, deployment and quality.
Each volume stands on its own, but they all start from what this one teaches.
Who this book is for
- For those who have never programmed, or have written only a few lines: the book teaches C# from scratch, taking nothing for granted, from the installation to the first
dotnet run. - For those who know another language and want C# done properly: classes, records, interfaces, delegates, generics and
nullas C# understands them, and threads measured rather than described. - For those who already know C# and want to move on to windows: chapters I.15–I.18 on threads,
Taskandawaitare the ones Volume 2 uses most, and that is where it pays to stop.
You need a computer with Windows, macOS or Linux, and the will to type the examples instead of only reading them.
How the book is organised
| Chapters | What |
|---|---|
| I.1–I.2 | from source to program, the .NET SDK, Visual Studio Code |
| I.3–I.5 | types, variables, expressions, decisions, loops, collections, methods |
| I.6–I.9 | classes and objects, inheritance and interfaces, delegates and events, generics, null and extensions |
| I.10–I.14 | errors and exceptions, files and text, JSON, XML, how to organise a program: MVC, MVP, MVVM |
| I.15–I.18 | threads, Task, async and await, and async in practice |
| Appendices | A–C: the quick reference, how the figures are made, the glossary |
Every chapter carries the number of its volume: I.6 is the sixth chapter of Volume 1, II.10 the tenth of Volume 2, and §I.6.3 the third section of chapter I.6. So a cross-reference such as “chapter I.16” also tells you which book to open.
Every chapter begins with What you will learn and ends with three boxes: Common mistakes, the mistakes people really make, with the remedy; Key points, the chapter in a few lines; Exercises, to do with the editor open. That is where the real learning happens.
Reading paths
- From zero. Everything, in order: each chapter uses the ones before it.
- You already know a language. Read chapters I.1 and I.2 for the tools, skim chapters I.3–I.5, and slow down from I.6 onwards, where C# has ideas of its own.
- You already know C#. Skim chapters I.1–I.13 to see the book's conventions, and read I.14 and I.15–I.18 in full.
The house rules
The code of the examples follows a few rules, always the same ones, and the book explains them along the way:
- only .NET, no other library;
- names in English, when they are ours:
Contact,Archive,Download; - one class per file, with the name of the file, and a comment on every method that says what it does and why;
- every handler is a method with a name, which says what it does;
- short lines, within 80 characters, so the code can be read on the page;
- nothing claimed, everything measured: when the book says that a program behaves in a certain way, a program has tried it, and the chapter tells the story.
The tools and the code of the examples
You need:
- the .NET 10 SDK, free, which chapter I.1 installs step by step;
- an editor: the book uses Visual Studio Code (chapter I.2), but any editor for C# will do.
All the code of the book, one project for each program of the examples, can be downloaded free of charge from the series website, https://raval.aratoingegneria.it. The examples are under the MIT licence: you can use them, change them and put them in your own programs, even in the ones you sell, as long as you keep the copyright notice.
Every program of the examples has been compiled without a single warning, and every figure has been drawn by the real program (Appendix B).
Typographical conventions
- A new term is in bold the first time, and it is in the glossary (Appendix C).
- Code, and the names of classes, methods and files, are in
fixed-width type. - Keys are written as you press them: Enter, Esc, Tab, Ctrl+C. On macOS, where the book writes Ctrl, it is usually Cmd.
- Paths are written as on Windows,
C:\Examples\I.3; on macOS and Linux the slashes go the other way, and the chapter says so wherever anything else changes. - Cross-references give the chapter, “(chapter I.16)”, or the section, “§I.16.4”.
- In the terminal figures the measured numbers (a time, a count) change a little every time the program runs: the text quotes them as the figure shows them.