1 hour ago · 13 min read2542 words · Tech · hide · 0 comments

This is the fourth post in the series: Exploring the .NET 11 preview. Part 1 - Running background tasks in Blazor with Web WorkersPart 2 - .NET (OK, C#) finally gets union types🎉Part 3 - Avoiding ToString() allocations with StringBuilder.MoveChunksPart 4 - Closed class hierarchies (this post) In this post I look at the implementation of closed class hierarchies that is available in .NET 11 preview 5. I'll describe what a close closed hierarchy is, how to create one, and discuss why you might want to. What is a "closed class hierarchy"? A closed class hierarchy is a class hierarchy that can only be defined within a single assembly. Attempting to derived from a closed class from a different assembly is a compilation error. This is easiest to see in action. Imagine you have the following classes, all in the same assembly: // Create a closed base class public closed class Animal { } // Each class derives from the closed Animal class public class Dog : Animal { } public class Cat : Animal…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.