© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
11 replies
Stroniax

✅ Struct Fields

Is there a reason to mask two values into a single field on a struct, e.g. if I want a
struct MyValue
struct MyValue
with fields
ushort A
ushort A
and
ushort B
ushort B
, is there any value in having the struct internally store the value as
uint _c
uint _c
? I formerly thought since this was one field it was better because everyone says to generally not use a struct with a lot of fields, but based on some reading I have done it seems that maybe this is treated in memory the same way since those two ushort fields are side-by-side and effectively storing two ushort fields would be no different except that I wouldn't have to manually unmask
A
A
and
B
B
from
_c
_c
in my getters.
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

❔ static fields for struct types
C#CC# / help
4y ago
❔ Can you modify fields in a struct?
C#CC# / help
3y ago
✅ Does C# have anonymous struct initializers for class fields?
C#CC# / help
9mo ago
difference between `struct` and `ref struct`
C#CC# / help
12mo ago