Learn extra at:
C# 14, a deliberate replace to Microsoft’s cross-platform, normal objective programming language, provides an extension member syntax to construct on the acquainted characteristic of extension strategies.
Extension members permit builders to “add” strategies to present sorts with out having to create a brand new derived kind, recompile, or in any other case modify the unique kind. The most recent C# 14 preview, launched with .NET 10 Preview 3, provides static extension strategies and occasion and static extension properties, in line with Kathleen Pollard, principal program supervisor for .NET at Microsoft, in a May 8 weblog publish.
Extension members additionally introduce an alternate syntax for extension strategies. The brand new syntax is optionally available, and builders don’t want to vary their present extension strategies. Whatever the fashion, extension members add performance to sorts. That is significantly helpful if builders don’t have entry to the sort’s supply code or if the sort is an interface, Pollard stated. If builders don’t like utilizing !listing.Any()
, they will create their very own extension methodology IsEmpty()
. Beginning within the newest preview, builders could make {that a} property and use it identical to every other property of the sort. Utilizing the brand new syntax, builders can also add extensions that work like static
properties and strategies on the underlying kind.