Microsoft wants safer C# without turning it into Rust

https://www.theregister.com/headlines.atom Hits: 41
Summary

DevOps Microsoft wants safer C# without turning it into Rust Unsafe bits get a warning label in planned low-level coding shake-up .NET product manager Richard Lander has written a lengthy post describing how the team intends to improve the memory safety of C# by introducing a new model and redefining the existing unsafe keyword, making the language more like Rust, though without giving up automatic memory management."We envision a future where C# is among a set of languages chosen and noted for the type- and memory-safety enforcement," said Lander. Many C# developers never use unsafe, but it has been part of the language from its first release. "Writing unsafe code is like writing C code within a C# program," said an early book called The C# Programming Language, written by its inventor Anders Hejlsberg and others. Examples of where unsafe code is necessary include interop with the underlying operating system, accessing memory-mapped devices, or implementing time-critical code. Unsafe code allows the use of pointer types, which are not tracked by the .NET garbage collector, and pointer operators. Other than that, the existing unsafe modifier has no effect on a type or member. This will change in C# 16, which is two versions in the future and will be released in late 2027, according to the usual annual .NET cycle, along with .NET 12, which will be a long-term support (LTS) release. Developers can also expect a preview in C# 15 and .NET 11. In the new model, marking a method as unsafe will "also mark it as requires-unsafe, meaning callers must be in an unsafe context and overrides cannot be unsafe if the base members is safe," states the current language proposal. This means that the unsafe designation propagates to callers until it is suppressed by including an unsafe context within a method, but not marking the method as unsafe.Some have questioned why the team will rely on the absence of unsafe to suppress propagation, rather than using the safe modifier. "I've bee...

First seen: 2026-05-26 19:39

Last seen: 2026-05-28 12:10