Part 6 in a series on new language features in C# 12.

C# logo

Inline arrays

Super-niche, but I guess if you need it, you’ll appreciate it. Previously you’d probably need to resort to using unsafe code to deal with this.

[System.Runtime.CompilerServices.InlineArray(10)]
public struct InlineArray
{
    public int Thing;
}

The compiler now knows this is an array of 10 contiguous elements.

Further reading

https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/struct?WT.mc_id=DOP-MVP-5001655#inline-arrays

Example source

https://github.com/flcdrg/csharp-12/blob/main/06-inline-arrays/InlineArrays.cs