C# 14 Lambda type inference with out parameter
| | |

C# 14: Simplified parameters with modifiers in lambdas

Lambda expressions have been a core feature of C# for many years, allowing developers to write inline functions or callbacks in a concise way. In C#, a lambda can have explicitly typed parameters (where you specify each parameter’s type) or implicitly typed parameters (where the types are inferred from context). Prior to C# 14, if…

C# 14 partial constructors
| | |

Partial constructors and events in C# 14

C# 14 introduces a new capability to declare instance constructors and events as partial members. This means you can split a constructor or event definition across two parts of a partial class, similar to how C# has long allowed partial methods and partial properties. This means that, one part of a partial class can declare…

Unbound generics used with nameof
| | |

C# 14: nameof support for unbound generic types

C# 14 introduces several small but helpful improvements to the language. One of these new features is an enhancement to the nameof expression – it now supports unbound generic types. In simple terms, you no longer need to plug in a placeholder type argument just to get the name of a generic type. This update…

Generic method type inference with Spans
| | |

Implicit Span conversions in C# 14 – First-class support for Span and ReadOnlySpan

C# 14 introduces a significant enhancement for high-performance code: first-class language support for spans. In particular, it adds new implicit conversions between Span<T>, ReadOnlySpan<T>, and arrays (T[]). This change makes it much easier to work with these types that represent safe, contiguous memory slices without extra allocations. In this article, we’ll explore what span conversions…

.NET 10 array ennumeration performance improvements (JIT array de-abstraction)
| |

.NET 10: Array ennumeration performance improvements (JIT array de-abstraction)

In .NET 10 Preview 1, the JIT compiler got better at optimizing how arrays are used with interfaces, especially when looping through them using foreach. This was the first step toward reducing the extra cost that comes with using enumerators to go through arrays. Preview 2 builds on this work with even more improvements. Take…

C# 14 field-backed properties
| | |

C# 14 – The field keyword and field-backed properties

C# 14 introduces a new contextual keyword, field, that can be used inside a property’s accessors (the get, set, or init blocks) to refer to the property’s backing storage​. In simpler terms, field is a placeholder representing the hidden variable where a property’s value is stored. This keyword lets you add custom logic to automatically…

ToArray performance in .NET 9 compared to .NET 8
| | |

.NET Performance: ToList vs ToArray

.NET 9 brings significant improvements to LINQ’s ToArray method, both in terms of speed, as well as memory allocation. To achieve this, the new implementation makes use of new runtime features such as InlineArray to significantly reduce memory allocations and improve speed, especially when dealing with an IEnumerable<T> of unknown length. If you’re curious about the implementation,…

An example of using C# 13 params with a ReadOnlySpan.
| | |

C# 13: Use params collections with any recognized collection type

The params modifier in C# has traditionally been associated with array types, allowing methods to accept a variable number of arguments. However, starting with C# 13, you can now use params collections with a variety of collection types, broadening its applicability and making your code even more versatile. Supported collection types The params modifier now…

| | |

How to switch to C# 13

While trying out C# 13 features, it’s possible you might come across errors similar to these: Feature is not available in C# 12.0. Please use language version 13.0 or later. or Error CS8652: The feature ‘<feature name>’ is currently in Preview and unsupported. To use Preview features, use the ‘preview’ language version. There are two…