Friday, March 2, 2018

c# - When to use struct?

When should you use struct and not class in C#? My conceptual model is that structs are used in times when the item is merely a collection of value types. A way to logically hold them all together into a cohesive whole.




I came across these rules here:




  • A struct should represent a single
    value.

  • A struct should have a memory
    footprint less than 16 bytes.

  • A struct should not be changed after
    creation.




Do these rules work? What does a struct mean semantically?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...