© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•6mo ago•
19 replies
peppy

Use of inline arrays to model arrays of structs

For a native type with the following shape:
public struct CHRDATA {
    public uint hp;
    public uint mp; // ... hundreds more fields
}
public struct SAVEDATA {
    public CHRDATA chr1;
    public CHRDATA chr2;   
    public CHRDATA chr3; // ... tens more entries
}
public struct CHRDATA {
    public uint hp;
    public uint mp; // ... hundreds more fields
}
public struct SAVEDATA {
    public CHRDATA chr1;
    public CHRDATA chr2;   
    public CHRDATA chr3; // ... tens more entries
}

it occurred to me I could represent the sequential
CHRDATA
CHRDATA
s with an
InlineArray
InlineArray
as such:
[InlineArray(80)]
public struct CHRDATA_ARRAY {
    private CHRDATA _c;
}
public struct SAVEDATA {
    public CHRDATA_ARRAY chrs;
}
[InlineArray(80)]
public struct CHRDATA_ARRAY {
    private CHRDATA _c;
}
public struct SAVEDATA {
    public CHRDATA_ARRAY chrs;
}

which raises a few questions, since I'm unfamiliar with the feature:
1) is this legal? can you make
InlineArrays
InlineArrays
of blittable structs, or should usage of
InlineArray
InlineArray
be restricted to primitives? (i.e.
int
int
,
float
float
)
2) does
chrs[62].hp = 300;
chrs[62].hp = 300;
in the above case operate on a copy or actually mutate the relevant part of
SAVEDATA
SAVEDATA
?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to use ExtensionMethods for structs
C#CC# / help
2y ago
❔ Benefit of ref structs
C#CC# / help
3y ago
Structs?
C#CC# / help
2y ago
❔ Sizing of Byte Arrays
C#CC# / help
3y ago