It's dangerous to code alone! Take this.

What's New in the 5th Edition

The 5th Edition is a relatively minor update from the 4th Edition, with the main goal to account for changes in C# 10, .NET 6, and Visual Studio 2022. I’d estimate that 96% of the content remained more or less the same (though every sentence got at least two more revision passes, so there are likely tiny clarity changes throughout the book).

Still, the C# language is evolving at a crazy rate. I’m shocked at how fast the language can evolve, even with 20+ years of life behind it. If C# 10 had just been minor tinkering, I’d have left 4th Edition well enough alone. But though the changes where comparatively minor for the book, I didn’t feel like I could ignore how C# has evolved in just a single year and update.

The major changes are these:

  • Updates for C# 10, .NET 6, and Visual Studio 2022
    • Level 3: Top-level statements are now the default. The 4th Edition said, “Make a new project, and then gut it and replace it with a simple System.Console.WriteLine("Hello, World!");”, but that is no longer necessary, if you’re using the right project template. This doesn’t make for a wildly different book, since the book assumed you were usign top-level statements anyway, but I also know that many readers ignored those instructions and used the old-style approach instead. That will probably happen less now.
    • Level 3 and Level 33: Some using directives are automatic now, including using System;, which means you won’t ever need to put a using directive into your programs for those super common namespaces. The code is simpler.
    • Level 22: Nullable type annotations are now on by default, meaning string now means “a definitely not null string” and string? now means “a possibly null string.” This feature was available in C# 9, but it was not on by default. It’s such a small thing, but it has a huge impact.
    • Level 28: Structs can now have field initializers and you can define a parameterless struct. In fact, Level 28 got quite a bit of revision.
    • Level 29: Records can now be classes or structs, whereas before, they could only be classes. Level 29 got quite a bit of revision because of this.
    • Level 33: There’s now the concept of a global using directive that you can add in one place and have it applied across every file in a project.
    • Level 33: You can now do “file scoped” namespace declarations (namespace SomeName;) and shed the extra curly braces and indentation.
    • Level 38: Lambdas can now support an explicit return type: int (int x) => x * 2;.
    • Level 40: Nested property patterns let you replace { Property1: { Property2: 0 } } with { Property1.Property2: 0 }.
  • I moved the discussion about local functions up from Level 34 to Level 13. Given that top-level statements that include methods are local functions, it seemed important to have that conversation earlier than 4th Edition was having it.
  • I had quite a few questions around scope, names, and code organization. Scattered through the book, but especially early on, I added in several “code map” diagrams to try to better explain the concepts of hierarchical code organization, scope, and names.
  • I removed a conversation in the book around “forever loops” being intentional infinite loops. That phrasing seems to be nearly non-existent in the programming world. I like the name, but didn’t want to give people the false idea that it was a thing programmers actually said when it has become clear to me that it isn’t.
  • A couple of very minor tweaks to challenges:
    • The Simula’s Soups challenge got cut down from an array of tuples to a single tuple. Lots of people struggled with this challenge in 4th Edition, and it was probably not fair to ask that people’s first real experience with tuples also included arrays.
    • The Automatic Tree Harvester challenge got some minor changes and some thematic improvements, getting renamed to Charberry Trees, but is mostly the same concept.

A few things that did not change:

  • No levels were added or removed.
  • Most sections stayed intact, aside from a couple of levels that were mentioned above.
  • The challenges are nearly all the same. No new challenges were added or removed, and only a few (mentioned above) were changed in minor ways.
  • The map and XP Tracker were essentially unchanged.

One thing I should probably mention now: I’m fully expecting C# 11 in November of 2022, and if so, I’m virtually certain to make a 6th Edition then. I know it can be frustrating to get a book that then gets (a tiny bit) out of date within a year, but the language changes so fast that I think it is extremely important and valuable to be providing up-to-date material for new C# programmers. (Though once again, I’m not currently expecting massive changes for 6th Edition beyond C# 11 features.)