Sunday, May 20, 2012

When to use struct in C#?


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?


Source: Tips4all

No comments:

Post a Comment