C# 12 features: Inline arrays
Part 6 in a series on new language features in C# 12.
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
Example source
https://github.com/flcdrg/csharp-12/blob/main/06-inline-arrays/InlineArrays.cs
Categories: .NET