Why is 16 byte the recommended size for struct in C#?

You’re misquoting the book (at least the 2nd edition). Jeffrey Richter states value types can be more than 16 bytes if:

You don’t intend to pass them to other
methods or copy them to and from a
collection class.

Additionally Eric Gunnerson adds (regarding the 16 byte limit)

Use this guideline as a trigger to do
more investigation.

It is simply not true that a struct “has to be less than 16 bytes in size”. It all depends on usage.

If you are creating the struct and also consuming it and are worried about performance then use a profiler comparing a struct vs class to see which works best for you.

Leave a Comment