Friday, 2 March 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...