Use of inline arrays to model arrays of structs
For a native type with the following shape:
it occurred to me I could represent the sequential
CHRDATA
s with an InlineArray
as such:
which raises a few questions, since I'm unfamiliar with the feature:
1) is this legal? can you make InlineArrays
of blittable structs, or should usage of InlineArray
be restricted to primitives? (i.e. int
, float
)
2) does chrs[62].hp = 300;
in the above case operate on a copy or actually mutate the relevant part of SAVEDATA
?1 Reply
1) try compile and see
2) the indexer returns the ref to
CHRDATA
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-12.0/inline-arrays#when-the-expression-type-is-intInline arrays, or fixed sized buffers - C# feature specifications
Inline arrays provide a general-purpose and safe mechanism for declaring inline arrays within C# classes, structs, and interfaces.