Paul Krill
Editor at Large

C# 12 boosts AOT compilation

news
Jul 18, 20232 mins

Latest C# 12 preview introduces an experimental feature that allows generators to reroute code to provide context-specific optimization.

detour sign
Credit: Thinkstock

C# 12, a planned upgrade to Microsoft’s signature object-oriented language for .NET development, introduces code rerouting to improve compilation, in the latest preview. The update also features access to inline arrays.

Available in Visual Studio 17.7 Preview 3 and .NET 8 Preview 6, both published July 11, the latest C# 12 preview includes features intended to enable future performance enhancements. Among these is an experimental feature dubbed interceptors that allows generators to reroute code, to provide context-specific optimization. C# 12 is set to ship as a final, production release with .NET 8 in the November time frame.

Interceptors are intended for advanced scenarios, allowing for better ahead-of-time (AOT) compilation. Attributes specify the actual source code location so interceptors generally only appropriate for source generators. As an experimental part of .NET 8, interceptors could be changed or removed at some point and thus should not be used in production.

Another capability, the nameof expression, which produces the name of a variable type or member as a string constant, has been enhanced to work in more places. The nameof keyword now works with member names including initializers, on static members, and in attributes.

Another C# 12 feature, the InlineArrayAttribute, was introduced to the runtime in a prior .NET 8 preview. This capability identifies a type that can be treated as a contiguous sequence of primitives for efficient, type-safe, overrun-safe, indexable and sliceable inline data. It is described as an advanced feature that will be used primarily by the compiler, .NET libraries, and other libraries. Inline arrays are used by .NET libraries to improve the performance of applications. 

Microsoft previously previewed other C# 12 features including optional parameters for lambda expressions, the ability to alias any type, and primary constructors, for adding parameters to a class declaration.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author