Struct or class?
Most types in a framework should be classes, but there are some situations in which the characteristics of a value type make it more appropriate to use structs.
Here are some things to consider:
๐ If your instances are small and short-lived, or commonly embedded in other objects, consider using a struct.
๐ However, be cautious when defining a struct. Only use it if the type represents a single value, is immutable, has an instance size under 16 bytes, and will not need to be boxed frequently.
Keep it in mind when defining new types in your code, and you’ll be able to make the best choice between a class or a struct.
๐ Adapted from my original post on LinkedIn .
