New features in C#14
The latest versions of .NET and C# were released last November.
C#14 brings some useful new features for everyday use. Here are the top 5 !
1. Extension members and extension blocks
Since C#3, it has been possible to define object extension methods as static methods within a static class using the following keyword:
C#14 allows you to do the same thing on properties. The new version also introduces the ability to create extensions on the type itself (as opposed to the instance). These are called as a static member. They can be a method, a property, or an operator.
The concept of extension blocks appears :
2. ️The keyword field in the property
With C#13, the code for a property with a private field remained very verbose:
C#14 introduces the field keyword, which significantly reduces code complexity:
3. ️Conditional null assignment
C#14 allows the ?. operator to be used directly on the left side of an assignment, thus avoiding the need to write explicit null conditions before assigning.
C# 13:
C #14 :
4. Implicit conversions to Span/ReadOnlySpan
C# 14 improves support for Span and ReadOnlySpan types by adding implicit conversions between them and arrays (T[]).
5. Modifiers in lambda parameters (out, ref, etc.)
Previously, the use of modifiers was conditional on explicitly specifying the parameter type:
C #14 allows you to switch:
Note that the params modifier is not affected.
❤️ In short, other new features
🔥 nameof can now be used with unbound generic types: nameof (List <>)
🔥 partial can be used to split the declaration and implementation of constructors and events in a partial class.
🔥 C#14 allows us to define compound assignment operators (+=, -=, etc.) in our types.










