C# 15 preview adds union types ahead of November release

The Register ·

Microsoft is preparing to launch C# 15 in November, with a preview build already showing its most heavily requested feature: union types. These let developers group several distinct custom data types under a single umbrella type, giving the compiler a fixed, verifiable list of permitted variants and enabling simpler pattern matching, custom functions for grouped types, and less boilerplate error-handling code. C# lead designer Mads Torgersen has championed the feature, arguing it lets developers express designs that traditional class hierarchies cannot.

The update also introduces "closed hierarchies," which restrict inheritance of a base class to derived types within the same assembly, blocking third-party subtypes and reducing compile errors. Separately, the unsafe keyword's role is being expanded beyond flagging risky memory operations to enforcing safety obligations on callers, echoing stricter approaches used in Rust and Swift. Other additions include collection expression arguments, indexers within extension blocks, and labelled break/continue statements for nested loops. The release continues the development of C#, created by Anders Hejlsberg and first launched by Microsoft in 2002, even as the company's broader focus has shifted towards cloud subscriptions and AI tools.

In short

  • C# 15 arrives in November with new union types feature
  • Unions let developers group custom types under one umbrella type
  • Unsafe keyword's scope expands, following Rust and Swift's approach

Explained simply

C# is a programming language made by Microsoft and first released in 2002. Developers use it to build software, and the language has been updated through successive versions.

Union types let a program describe a value that can be one of a defined set of different types. This can help developers handle related possibilities with clearer checks and less repeated code. C#’s lead designer, Mads Torgersen, has argued that the feature can represent designs that are awkward to express with class inheritance.

Other proposed changes include limiting which types can inherit from a base class, and making the unsafe keyword place clearer safety duties on code that calls certain operations. These changes matter to developers because language rules affect how easily software can be written and checked; they also show Microsoft continuing to develop C# alongside its other products.

Software

Read the full article at the source →

Originally published by The Register as “Microsoft devs rejoice: Union types coming to C# in November”.

Log in to join the discussion