I was reading into the nitty-gritty of structs in C# here: \"C Fundamentals, The
ID: 646068 • Letter: I
Question
I was reading into the nitty-gritty of structs in C# here: "C Fundamentals, The differences between struct and class." and at the very bottom it mentions keeping a struct below 16 bytes. I looked elsewhere and saw that it is commonly recommended, though it sounds like it's been bumped up a bit to 20-24 bytes here in later versions of .NET.
My question is, are they just adding up the ints, doubles, etc. to total the 16 bytes, or are they talking about the size after compile, and if so, wouldn't getters and setters add to that?
Explanation / Answer
The size of a struct refers to the struct's fields.
Automatic Properties include a field as part of their compiled structure; this field counts towards the size of the struct.
Otherwise, properties are no different from functions - they are not part of the struct's instance at all, since there's nothing particular to that instance in the property.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.