C# 14 introduces extension members, a significant evolution beyond the classic extension methods available since C# 3.0. While traditional extension methods were limited to instance methods requiring static classes and the `this` keyword, the new `extension` block syntax supports instance and static properties, methods, and operators. The article walks through a classic extension method example on `DateTime`, then shows how to convert it to the new syntax using an `extension` block inside a static class. The new approach eliminates the need for `this` on each member, enables static member extensions, and allows calling extensions without creating an instance first. Existing code remains compatible, and JetBrains Rider provides an intention action to migrate classic extension methods to the new block syntax automatically.
Table of contents
Overview: What are extension members?Classic extension methodsExtension members in C# 14In Summary1 Comment
Sort: